The Battle for Wesnoth  1.13.10+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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

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

Definition at line 135 of file lua_cpp_function.hpp.

Function Documentation

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

Definition at line 102 of file lua_cpp_function.cpp.

References f, lua_upvalueindex, and luaL_checkudata().

Referenced by push_closure().

static int lua_cpp::intf_dispatcher ( lua_State L)
static

Definition at line 36 of file lua_cpp_function.cpp.

References f, lua_remove, and luaL_checkudata().

Referenced by register_metatable().

static int lua_cpp::intf_tostring ( lua_State L)
static

Definition at line 60 of file lua_cpp_function.cpp.

References d, lua_pushstring(), and luaL_checkudata().

Referenced by register_metatable().

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 108 of file lua_cpp_function.cpp.

References intf_closure_dispatcher(), lua_insert, lua_pushcclosure(), and push_function().

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

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 85 of file lua_cpp_function.cpp.

References luaL_setmetatable().

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

void lua_cpp::register_metatable ( lua_State L)
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 91 of file lua_cpp_function.cpp.

References lua_setfield(), luaL_checkversion, and push_function().

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

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 115 of file lua_cpp_function.cpp.

References i, lua_pop, lua_pushvalue(), lua_setfield(), luaL_checkstack(), luaL_checkversion, and push_closure().

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 168 of file lua_cpp_function.hpp.

References i, and set_functions().

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 203 of file lua_cpp_function.hpp.

References i, and set_functions().

Variable Documentation

char const* lua_cpp::cpp_function = "CPP_Function"

Definition at line 34 of file lua_cpp_function.cpp.