27 #define DBG_LUA LOG_STREAM(debug, log_scripting_lua)
28 #define LOG_LUA LOG_STREAM(info, log_scripting_lua)
29 #define WRN_LUA LOG_STREAM(warn, log_scripting_lua)
30 #define ERR_LUA LOG_STREAM(err, log_scripting_lua)
50 ERR_LUA <<
"lua_cpp::intf_cleanup called on data of type: " << lua_typename( L, lua_type( L, 1 ) );
51 ERR_LUA <<
"This may indicate a memory leak, please report at bugs.wesnoth.org";
52 lua_pushstring(L,
"C++ function object garbage collection failure");
64 std::stringstream result;
65 result <<
"c++ function: " << std::hex <<
d;
66 lua_pushstring(L, result.str().c_str());
74 lua_setfield(L, -2,
"__call");
76 lua_setfield(L, -2,
"__gc");
78 lua_setfield(L, -2,
"__tostring");
79 lua_pushstring(L,
"function");
80 lua_setfield(L, -2,
"__metatable");
82 lua_setfield(L, -2,
"__index");
93 void set_functions( lua_State* L,
const std::vector<lua_cpp::Reg>& functions)
97 if (l.name !=
nullptr) {
99 lua_setfield(L, -2, l.name);
113 lua_insert(L, -(1+nup));
117 void set_functions( lua_State* L,
const std::vector<lua_cpp::Reg>& functions,
int nup )
119 luaL_checkversion(L);
120 luaL_checkstack(L, nup+1,
"too many upvalues");
122 if (l.name ==
nullptr) {
126 for (
i = 0;
i < nup; ++
i)
127 lua_pushvalue(L, -nup);
129 lua_setfield(L, -(nup + 2), l.name);
Standard logging facilities (interface).
static lg::log_domain log_scripting_lua("scripting/lua")
static int intf_cleanup(lua_State *L)
void register_metatable(lua_State *L)
static int intf_dispatcher(lua_State *L)
void push_function(lua_State *L, const lua_function &f)
Pushes a std::function wrapper object onto the stack.
static int intf_closure_dispatcher(lua_State *L)
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,...
static int intf_tostring(lua_State *L)
char const * cpp_function
std::function< int(lua_State *)> lua_function
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.