Classes | Typedefs | Functions
luwra Namespace Reference

Classes

struct  Arbitrary
 
struct  GlobalAccessor
 
struct  NativeFunction
 
struct  NativeFunction< R(A...)>
 
struct  NativeFunction< void(A...)>
 
struct  Pushable
 
struct  StateWrapper
 
struct  Value
 
struct  Value< Arbitrary >
 
struct  Value< bool >
 
struct  Value< CFunction >
 
struct  Value< char[n]>
 
struct  Value< const char * >
 
struct  Value< const char[n]>
 
struct  Value< const T >
 
struct  Value< double >
 
struct  Value< FieldVector >
 
struct  Value< float >
 
struct  Value< long double >
 
struct  Value< NativeFunction< R(A...)> >
 
struct  Value< Pushable >
 
struct  Value< signedchar >
 
struct  Value< signedint >
 
struct  Value< signedlong int >
 
struct  Value< signedlong long int >
 
struct  Value< signedshort >
 
struct  Value< std::nullptr_t >
 
struct  Value< std::string >
 
struct  Value< std::tuple< A... > >
 
struct  Value< U & >
 
struct  Value< U * >
 
struct  Value< unsigned char >
 
struct  Value< unsigned int >
 
struct  Value< unsigned long int >
 
struct  Value< unsigned long long int >
 
struct  Value< unsigned short >
 
struct  Value< volatile T >
 

Typedefs

using FieldVector = std::vector< std::pair< Pushable, Pushable >>
 
using Integer = lua_Integer
 
using Number = lua_Number
 
using State = lua_State
 
using CFunction = lua_CFunction
 

Functions

static bool equal (State *state, int index1, int index2)
 
static void setMetatable (State *state, const char *name)
 
template<typename V >
static void setGlobal (State *state, const std::string &name, V value)
 
template<typename V >
static V getGlobal (State *state, const std::string &name)
 
template<typename... R>
static void setFields (State *state, int index, R &&...args)
 
static void setFields (State *state, int index, const FieldVector &fields)
 
template<typename V , typename K >
static V getField (State *state, int index, K key)
 
template<typename S , typename F , typename... X>
static internal::Layout< S >::ReturnType direct (State *state, int pos, F &&hook, X &&...args)
 
template<typename S , typename F , typename... A>
static internal::Layout< S >::ReturnType direct (State *state, F &&hook, A &&...args)
 
template<typename R , typename... A>
static R apply (State *state, int pos, R(*fun)(A...))
 
template<typename R , typename... A>
static R apply (State *state, R(*fun)(A...))
 
template<typename R , typename... A>
static R apply (State *state, int pos, const std::function< R(A...)> &fun)
 
template<typename R , typename... A>
static R apply (State *state, const std::function< R(A...)> &fun)
 
template<typename S , typename F , typename... A>
static size_t map (State *state, int pos, F &&hook, A &&...args)
 
template<typename S , typename F , typename... A>
static size_t map (State *state, F &&hook, A &&...args)
 
template<typename T >
static size_t push (State *state, T value)
 
template<typename T1 , typename T2 , typename... TR>
size_t push (State *state, T1 value, T2 &&head, TR &&...rest)
 
template<typename T >
static T read (State *state, int index)
 
template<typename U , typename... A>
static internal::StripUserType< U > & construct (State *state, A &&...args)
 
template<typename U >
static void registerUserType (State *state, const FieldVector &methods=FieldVector(), const FieldVector &meta_methods=FieldVector())
 
template<typename T >
static void registerUserType (State *state, const std::string &ctor_name, const FieldVector &methods=FieldVector(), const FieldVector &meta_methods=FieldVector())
 

Typedef Documentation

using luwra::CFunction = typedef lua_CFunction
using luwra::FieldVector = typedef std::vector<std::pair<Pushable, Pushable>>

A collection of key-value pairs.

using luwra::Integer = typedef lua_Integer
using luwra::Number = typedef lua_Number
using luwra::State = typedef lua_State

Function Documentation

template<typename R , typename... A>
static R luwra::apply ( State state,
int  pos,
R(*)(A...)  fun 
)
inlinestatic

Synonym for direct with a function pointer which lets you omit all template parameters. The stack layout will be inferred using the signature of the given function pointer.

template<typename R , typename... A>
static R luwra::apply ( State state,
R(*)(A...)  fun 
)
inlinestatic

Same as apply(state, 1, fun).

template<typename R , typename... A>
static R luwra::apply ( State state,
int  pos,
const std::function< R(A...)> &  fun 
)
inlinestatic

Synonym for direct with a function object which lets you omit all template parameters. The stack layout will be inferred using the template parameter to your std::function object.

template<typename R , typename... A>
static R luwra::apply ( State state,
const std::function< R(A...)> &  fun 
)
inlinestatic

Same as apply(state, 1, fun).

template<typename U , typename... A>
static internal::StripUserType<U>& luwra::construct ( State state,
A &&...  args 
)
inlinestatic

Construct a user type value on the stack.

Note
Instances created using this specialization are allocated and constructed as full user data types in Lua. The default garbage-collecting hook will destruct the user type, once it has been marked.
Parameters
stateLua state
argsConstructor arguments
Returns
Reference to the constructed value
template<typename S , typename F , typename... X>
static internal::Layout<S>::ReturnType luwra::direct ( State state,
int  pos,
F &&  hook,
X &&...  args 
)
inlinestatic

Retrieve values from the stack and invoke a Callable with them.

Template Parameters
SSignature in the form of R(A...) where A is a sequence of types, which shall be retrieved from the stack, and R the return type of hook
FAn instance of Callable which accepts parameters X..., A... and returns R (this parameter should be inferable and can be omitted)
XExtra argument types
Parameters
stateLua state instance
posIndex of the first value
hookCallable value
argsExtra arguments which shall be be passed to hook before the stack values
Returns
Result of calling hook
template<typename S , typename F , typename... A>
static internal::Layout<S>::ReturnType luwra::direct ( State state,
F &&  hook,
A &&...  args 
)
inlinestatic

Same as direct(state, 1, hook).

static bool luwra::equal ( State state,
int  index1,
int  index2 
)
inlinestatic

Check if two values are equal.

Parameters
stateLua state
index1Index of left-hand side value
index2Index of right-hand side value
template<typename V , typename K >
static V luwra::getField ( State state,
int  index,
key 
)
inlinestatic

Retrieve a field from a table.

template<typename V >
static V luwra::getGlobal ( State state,
const std::string &  name 
)
inlinestatic

Retrieve a global value.

Parameters
stateLua state
nameGlobal name
Returns
Value associated with the given name
template<typename S , typename F , typename... A>
static size_t luwra::map ( State state,
int  pos,
F &&  hook,
A &&...  args 
)
inlinestatic

Similiar to direct but pushes the result of the given Callable onto the stack.

Returns
Number of values pushed
template<typename S , typename F , typename... A>
static size_t luwra::map ( State state,
F &&  hook,
A &&...  args 
)
inlinestatic

Same as map(state, 1, hook).

template<typename T >
static size_t luwra::push ( State state,
value 
)
inlinestatic

Convenient wrapped for Value<T>::push.

template<typename T1 , typename T2 , typename... TR>
size_t luwra::push ( State state,
T1  value,
T2 &&  head,
TR &&...  rest 
)

Allows you to push multiple values at once.

template<typename T >
static T luwra::read ( State state,
int  index 
)
inlinestatic

Convenient wrapper for Value<T>::read.

template<typename U >
static void luwra::registerUserType ( State state,
const FieldVector methods = FieldVector(),
const FieldVector meta_methods = FieldVector() 
)
inlinestatic

Register the metatable for user type T. This function allows you to register methods which are shared across all instances of this type.

By default a garbage-collector hook and string representation function are added as meta methods. Both can be overwritten.

Template Parameters
UUser type struct or class
Parameters
stateLua state
methodsMap of methods
meta_methodsMap of meta methods
template<typename T >
static void luwra::registerUserType ( State state,
const std::string &  ctor_name,
const FieldVector methods = FieldVector(),
const FieldVector meta_methods = FieldVector() 
)
inlinestatic

Same as the other registerUserType but registers the construtor as well. The template parameter is a signature U(A...) where U is the user type and A... its constructor parameters.

template<typename... R>
static void luwra::setFields ( State state,
int  index,
R &&...  args 
)
inlinestatic

Set multiple fields at once. Allows you to provide multiple key-value pairs.

Parameters
stateLua state
indexTable index
argsKey-value pairs
static void luwra::setFields ( State state,
int  index,
const FieldVector fields 
)
inlinestatic

Apply key-value pairs to a table.

Parameters
stateLua state
indexTable index
fieldsTable fields
template<typename V >
static void luwra::setGlobal ( State state,
const std::string &  name,
value 
)
inlinestatic

Register a value as a global.

Parameters
stateLua state
nameGlobal name
valueGlobal value
static void luwra::setMetatable ( State state,
const char *  name 
)
inlinestatic

Set a registered metatable for the value on top of the stack.

Parameters
stateLua state
nameMetatable name