Otclient  14/8/2020
luabinder Namespace Reference

Classes

struct  bind_lambda_fun
 Specialization for lambdas. More...
 
struct  bind_lambda_fun< Ret(Lambda::*)(Args...) const >
 
struct  connect_lambda
 
struct  connect_lambda< Ret(Lambda::*)(Args...) const >
 
struct  expand_fun_arguments
 Expand arguments from tuple for later calling the C++ function. More...
 
struct  expand_fun_arguments< 0, Ret >
 
struct  pack_values_into_tuple
 Pack arguments from lua stack into a tuple recursively. More...
 
struct  pack_values_into_tuple< 0 >
 

Functions

template<typename Ret , typename F , typename... Args>
std::enable_if<!std::is_void< Ret >::value, int >::type call_fun_and_push_result (const F &f, LuaInterface *lua, const Args &... args)
 C++ function caller that can push results to lua. More...
 
template<typename Ret , typename F , typename... Args>
std::enable_if< std::is_void< Ret >::value, int >::type call_fun_and_push_result (const F &f, LuaInterface *lua, const Args &... args)
 C++ void function caller. More...
 
template<typename Ret , typename F , typename Tuple >
LuaCppFunction bind_fun_specializer (const F &f)
 Bind different types of functions generating a lambda. More...
 
LuaCppFunction bind_fun (const std::function< int(LuaInterface *)> &f)
 Bind a customized function. More...
 
template<typename Ret , typename... Args>
LuaCppFunction bind_fun (const std::function< Ret(Args...)> &f)
 Bind a std::function. More...
 
template<typename Lambda >
std::enable_if< std::is_constructible< decltype(&Lambda::operator())>::value, LuaCppFunction >::type bind_fun (const Lambda &f)
 
template<typename Ret , typename... Args>
LuaCppFunction bind_fun (Ret(*f)(Args...))
 Convert to C++ functions pointers to std::function then bind. More...
 
template<typename Ret , typename C , typename... Args>
std::function< Ret(const stdext::shared_object_ptr< C > &, const Args &...)> make_mem_func (Ret(C::*f)(Args...))
 Create member function lambdas. More...
 
template<typename C , typename... Args>
std::function< void(const stdext::shared_object_ptr< C > &, const Args &...)> make_mem_func (void(C::*f)(Args...))
 
template<typename Ret , typename C , typename... Args>
std::function< Ret(const Args &...)> make_mem_func_singleton (Ret(C::*f)(Args...), C *instance)
 Create member function lambdas for singleton classes. More...
 
template<typename C , typename... Args>
std::function< void(const Args &...)> make_mem_func_singleton (void(C::*f)(Args...), C *instance)
 
template<typename C , typename Ret , class FC , typename... Args>
LuaCppFunction bind_mem_fun (Ret(FC::*f)(Args...))
 Bind member functions. More...
 
template<typename C , typename Ret , class FC , typename... Args>
LuaCppFunction bind_singleton_mem_fun (Ret(FC::*f)(Args...), C *instance)
 Bind singleton member functions. More...
 
template<typename C >
LuaCppFunction bind_mem_fun (int(C::*f)(LuaInterface *))
 Bind customized member functions. More...
 

Detailed Description

This namespace contains some dirty metaprogamming that uses a lot of C++0x features The purpose here is to create templates that can bind any function from C++ and expose in lua environment. This is done combining variadic templates, lambdas, tuples and some type traits features from the new C++0x standard to create templates that can detect functions's arguments and then generate lambdas. These lambdas pops arguments from lua stack, call the bound C++ function and then pushes the result to lua.

Function Documentation

◆ bind_fun() [1/4]

template<typename Lambda >
std::enable_if<std::is_constructible<decltype(&Lambda::operator())>::value, LuaCppFunction>::type luabinder::bind_fun ( const Lambda &  f)

Definition at line 139 of file luabinder.h.

◆ bind_fun() [2/4]

LuaCppFunction luabinder::bind_fun ( const std::function< int(LuaInterface *)> &  f)
inline

Bind a customized function.

Definition at line 110 of file luabinder.h.

Here is the caller graph for this function:

◆ bind_fun() [3/4]

template<typename Ret , typename... Args>
LuaCppFunction luabinder::bind_fun ( const std::function< Ret(Args...)> &  f)

Bind a std::function.

Definition at line 116 of file luabinder.h.

◆ bind_fun() [4/4]

template<typename Ret , typename... Args>
LuaCppFunction luabinder::bind_fun ( Ret(*)(Args...)  f)

Convert to C++ functions pointers to std::function then bind.

Definition at line 146 of file luabinder.h.

Here is the call graph for this function:

◆ bind_fun_specializer()

template<typename Ret , typename F , typename Tuple >
LuaCppFunction luabinder::bind_fun_specializer ( const F &  f)

Bind different types of functions generating a lambda.

Definition at line 93 of file luabinder.h.

Here is the call graph for this function:

◆ bind_mem_fun() [1/2]

template<typename C >
LuaCppFunction luabinder::bind_mem_fun ( int(C::*)(LuaInterface *)  f)

Bind customized member functions.

Definition at line 206 of file luabinder.h.

◆ bind_mem_fun() [2/2]

template<typename C , typename Ret , class FC , typename... Args>
LuaCppFunction luabinder::bind_mem_fun ( Ret(FC::*)(Args...)  f)

Bind member functions.

Definition at line 185 of file luabinder.h.

◆ bind_singleton_mem_fun()

template<typename C , typename Ret , class FC , typename... Args>
LuaCppFunction luabinder::bind_singleton_mem_fun ( Ret(FC::*)(Args...)  f,
C *  instance 
)

Bind singleton member functions.

Definition at line 195 of file luabinder.h.

Here is the caller graph for this function:

◆ call_fun_and_push_result() [1/2]

template<typename Ret , typename F , typename... Args>
std::enable_if<!std::is_void<Ret>::value, int>::type luabinder::call_fun_and_push_result ( const F &  f,
LuaInterface lua,
const Args &...  args 
)

C++ function caller that can push results to lua.

Definition at line 61 of file luabinder.h.

Here is the call graph for this function:

◆ call_fun_and_push_result() [2/2]

template<typename Ret , typename F , typename... Args>
std::enable_if<std::is_void<Ret>::value, int>::type luabinder::call_fun_and_push_result ( const F &  f,
LuaInterface lua,
const Args &...  args 
)

C++ void function caller.

Definition at line 70 of file luabinder.h.

◆ make_mem_func() [1/2]

template<typename Ret , typename C , typename... Args>
std::function<Ret(const stdext::shared_object_ptr<C>&, const Args&...)> luabinder::make_mem_func ( Ret(C::*)(Args...)  f)

Create member function lambdas.

Definition at line 152 of file luabinder.h.

Here is the call graph for this function:

◆ make_mem_func() [2/2]

template<typename C , typename... Args>
std::function<void(const stdext::shared_object_ptr<C>&, const Args&...)> luabinder::make_mem_func ( void(C::*)(Args...)  f)

Definition at line 161 of file luabinder.h.

Here is the call graph for this function:

◆ make_mem_func_singleton() [1/2]

template<typename Ret , typename C , typename... Args>
std::function<Ret(const Args&...)> luabinder::make_mem_func_singleton ( Ret(C::*)(Args...)  f,
C *  instance 
)

Create member function lambdas for singleton classes.

Definition at line 172 of file luabinder.h.

◆ make_mem_func_singleton() [2/2]

template<typename C , typename... Args>
std::function<void(const Args&...)> luabinder::make_mem_func_singleton ( void(C::*)(Args...)  f,
C *  instance 
)

Definition at line 177 of file luabinder.h.