Orxonox  0.0.5 Codename: Arcturus
Classes | Static Public Member Functions | Private Member Functions | Static Private Member Functions | Static Private Attributes | List of all members
LuaTBTypedStack Class Reference

Represents a typed version of the lua stack. More...

#include </home/jenkins/workspace/orxonox_doxygen_trunk/src/orxonox/scriptablecontroller/luatb_typed_stack.h>

Classes

struct  GetLuaCallback
 
struct  function< Ret(Args...)>
 Needed to get a lambda to call a lua function. More...
 

Static Public Member Functions

template<typename T >
static std::enable_if<!IsCallable< T >::value, T >::type getArgument (lua_State *lua)
 Get a non-function argument from the lua stack and convert it to type 'T'. More...
 
template<typename T >
static std::enable_if< IsCallable< T >::value, T >::type getArgument (lua_State *lua)
 Get a function-type argument from the lua stack and convert it to type 'T'. More...
 

Private Member Functions

template<>
int getFromLuaStack (lua_State *lua)
 
template<>
double getFromLuaStack (lua_State *lua)
 
template<>
void pushToLuaStack (lua_State *lua, int value)
 
template<>
void pushToLuaStack (lua_State *lua, double value)
 

Static Private Member Functions

template<typename Ret , typename... Args>
static void callLuaFunction (lua_State *lua, int *ref, Args...args)
 Pushes all arguments to the lua stack and calls a lua function afterwards. More...
 
template<typename T >
static T getFromLuaStack (lua_State *lua)
 Get a value from the lua stack and convert it to type 'T'. More...
 
template<typename T >
static void pushArgumentsToLuaStack (lua_State *, T)
 Pushes nothing onto the stack. More...
 
template<typename First , typename... Args>
static void pushArgumentsToLuaStack (lua_State *lua, First first, Args...args)
 Recursively pushes arguments to the lua stack. More...
 
template<typename T >
static void pushToLuaStack (lua_State *lua, T value)
 Pushes a value to the lua stack. More...
 

Static Private Attributes

static std::list< std::unique_ptr< int > > callbackRefs = {}
 

Detailed Description

Represents a typed version of the lua stack.

We need a separate class for this because we need to specialize the functions and that's not possible if we didn't specialize the class. And the logical separation makes sense as well.

Member Function Documentation

template<typename Ret , typename... Args>
static void LuaTBTypedStack::callLuaFunction ( lua_State *  lua,
int *  ref,
Args...  args 
)
inlinestaticprivate

Pushes all arguments to the lua stack and calls a lua function afterwards.

Parameters
luaPointer to the lua state
refPointer to the lua registry reference where the function is stored
argsArguments for the function
template<typename T >
static std::enable_if<!IsCallable<T>::value, T>::type LuaTBTypedStack::getArgument ( lua_State *  lua)
inlinestatic

Get a non-function argument from the lua stack and convert it to type 'T'.

Parameters
luaPointer to the lua state
Returns
Top element of the lua stack with the appropriate type

Note: Pops the value from the stack.

template<typename T >
static std::enable_if<IsCallable<T>::value, T>::type LuaTBTypedStack::getArgument ( lua_State *  lua)
inlinestatic

Get a function-type argument from the lua stack and convert it to type 'T'.

Parameters
luaPointer to the lua state
Returns
Top element of the lua stack with the appropriate type

Specialization if 'T' is a callable type (std::function). Saves the lua function in the registry and constructs a function to call it again.

Note: Pops the value from the stack.

template<>
int LuaTBTypedStack::getFromLuaStack ( lua_State *  lua)
private
template<>
double LuaTBTypedStack::getFromLuaStack ( lua_State *  lua)
private
template<typename T >
static T LuaTBTypedStack::getFromLuaStack ( lua_State *  lua)
staticprivate

Get a value from the lua stack and convert it to type 'T'.

Parameters
luaPointer to the lua state
Returns
Top element of the lua stack with the appropriate type

Note: Does NOT pop the value from the stack.

template<typename T >
static void LuaTBTypedStack::pushArgumentsToLuaStack ( lua_State *  ,
 
)
inlinestaticprivate

Pushes nothing onto the stack.

This is needed in case the function has no arguments at all. Otherwise, we would have a missing argument for such a function. This is also why we pass a dummy argument in 'callLuaFunction', so we have at least one argument. It is the termination point for the recursive template.

template<typename First , typename... Args>
static void LuaTBTypedStack::pushArgumentsToLuaStack ( lua_State *  lua,
First  first,
Args...  args 
)
inlinestaticprivate

Recursively pushes arguments to the lua stack.

Parameters
luaPointer to the lua state
firstFirst argument to push onto the stack
argsThe remaining arguments to push onto the stack
template<>
void LuaTBTypedStack::pushToLuaStack ( lua_State *  lua,
int  value 
)
private
template<>
void LuaTBTypedStack::pushToLuaStack ( lua_State *  lua,
double  value 
)
private
template<typename T >
static void LuaTBTypedStack::pushToLuaStack ( lua_State *  lua,
value 
)
staticprivate

Pushes a value to the lua stack.

Parameters
luaPointer to the lua state
valueThe value to push

Note: Only the specializations are valid

Member Data Documentation

std::list< std::unique_ptr< int > > LuaTBTypedStack::callbackRefs = {}
staticprivate

The documentation for this class was generated from the following files: