The Battle for Wesnoth  1.19.5+dev
Classes | Typedefs | Functions | Variables
lua_cpp Namespace Reference

Classes

struct  Reg
 

Typedefs

typedef std::function< int(lua_State *)> lua_function
 

Functions

static int intf_dispatcher (lua_State *L)
 
static int intf_cleanup (lua_State *L)
 
static int intf_tostring (lua_State *L)
 
void register_metatable (lua_State *L)
 
void push_function (lua_State *L, const lua_function &f)
 Pushes a std::function wrapper object onto the stack. More...
 
void set_functions (lua_State *L, const std::vector< lua_cpp::Reg > &functions)
 Analogous to lua_setfuncs, it registers a collection of function wrapper objects into a table, using push_function. More...
 
static int intf_closure_dispatcher (lua_State *L)
 
void push_closure (lua_State *L, const lua_function &f, int nup)
 Pushes a closure which retains a std::function object as its first up-value. More...
 
void set_functions (lua_State *L, const std::vector< lua_cpp::Reg > &functions, int nup)
 Analogous to lua_setfuncs and set_functions above, but pushes closures. More...
 
template<int N>
void set_functions (lua_State *L, const lua_cpp::Reg(&functions)[N])
 Analogous to lua_setfuncs, it registers a collection of function wrapper objects into a table, using push_function. More...
 
template<int N>
void set_functions (lua_State *L, const lua_cpp::Reg(&functions)[N], int nup)
 Analogous to lua_setfuncs and set_functions above, but pushes closures. More...
 

Variables

char const * cpp_function = "CPP_Function"
 

Typedef Documentation

◆ lua_function

typedef std::function<int(lua_State*)> lua_cpp::lua_function

Definition at line 136 of file lua_cpp_function.hpp.

Function Documentation

◆ intf_cleanup()

static int lua_cpp::intf_cleanup ( lua_State *  L)
static

Definition at line 46 of file lua_cpp_function.cpp.

References cpp_function, d, and ERR_LUA.

Referenced by register_metatable().

◆ intf_closure_dispatcher()

static int lua_cpp::intf_closure_dispatcher ( lua_State *  L)
static

Definition at line 104 of file lua_cpp_function.cpp.

References cpp_function, and f.

Referenced by push_closure().

◆ intf_dispatcher()

static int lua_cpp::intf_dispatcher ( lua_State *  L)
static

Definition at line 36 of file lua_cpp_function.cpp.

References cpp_function, and f.

Referenced by register_metatable().

◆ intf_tostring()

static int lua_cpp::intf_tostring ( lua_State *  L)
static

Definition at line 60 of file lua_cpp_function.cpp.

References cpp_function, and d.

Referenced by register_metatable().

◆ push_closure()

void lua_cpp::push_closure ( lua_State *  L,
const lua_function f,
int  nup 
)

Pushes a closure which retains a std::function object as its first up-value.

Note that this is NOT strictly compatible with the lua c function push_closure – if you request additional upvalues they will be indexed starting at 2 rather than 1.

Note that unlike push_function above this results in a function and not userdata being pushed on the stack.

Definition at line 110 of file lua_cpp_function.cpp.

References f, intf_closure_dispatcher(), and push_function().

Referenced by game_lua_kernel::impl_theme_items_get(), and set_functions().

◆ push_function()

void lua_cpp::push_function ( lua_State *  L,
const lua_function f 
)

Pushes a std::function wrapper object onto the stack.

It does not support up-values. If you need that use push_closure (a little slower).

NOTE: This object has type userdata, not function. Its metatable has a call operator. If this is not sufficient for your needs then use push_closure.

Definition at line 87 of file lua_cpp_function.cpp.

References cpp_function, and f.

Referenced by push_closure(), application_lua_kernel::thread::run_script(), and set_functions().

◆ register_metatable()

void lua_cpp::register_metatable ( lua_State *  L)

◆ set_functions() [1/4]

template<int N>
void lua_cpp::set_functions ( lua_State *  L,
const lua_cpp::Reg(&)  functions[N] 
)

Analogous to lua_setfuncs, it registers a collection of function wrapper objects into a table, using push_function.

The note above applies.

Definition at line 169 of file lua_cpp_function.hpp.

References i, and set_functions().

◆ set_functions() [2/4]

template<int N>
void lua_cpp::set_functions ( lua_State *  L,
const lua_cpp::Reg(&)  functions[N],
int  nup 
)

Analogous to lua_setfuncs and set_functions above, but pushes closures.

NOTE: set_functions(L, l, 0) is NOT the same as set_functions(L, l), as the latter produces userdata and the former doesn't.

Definition at line 204 of file lua_cpp_function.hpp.

References i, and set_functions().

◆ set_functions() [3/4]

void lua_cpp::set_functions ( lua_State *  L,
const std::vector< lua_cpp::Reg > &  functions 
)

Analogous to lua_setfuncs, it registers a collection of function wrapper objects into a table, using push_function.

The note above applies.

Definition at line 93 of file lua_cpp_function.cpp.

References push_function().

Referenced by game_lua_kernel::game_lua_kernel(), lua_gui2::luaW_open(), and set_functions().

◆ set_functions() [4/4]

void lua_cpp::set_functions ( lua_State *  L,
const std::vector< lua_cpp::Reg > &  functions,
int  nup 
)

Analogous to lua_setfuncs and set_functions above, but pushes closures.

NOTE: set_functions(L, l, 0) is NOT the same as set_functions(L, l), as the latter produces userdata and the former doesn't.

Definition at line 117 of file lua_cpp_function.cpp.

References i, and push_closure().

Variable Documentation

◆ cpp_function

char const* lua_cpp::cpp_function = "CPP_Function"