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");
63 lua_pushstring(L,
" function: C++");
70 lua_getinfo(L,
">S", &
info);
71 std::stringstream result;
72 result <<
"function: " <<
info.what;
73 lua_pushstring(L, result.str().c_str());
81 lua_setfield(L, -2,
"__call");
83 lua_setfield(L, -2,
"__gc");
85 lua_setfield(L, -2,
"__tostring");
86 lua_pushstring(L,
"function");
87 lua_setfield(L, -2,
"__metatable");
89 lua_setfield(L, -2,
"__index");
95 lua_createtable(L, 0, 1);
97 lua_setfield(L, -2,
"__tostring");
98 lua_pushstring(L,
"function");
99 lua_setfield(L, -2,
"__metatable");
100 lua_setmetatable(L, -2);
109 void set_functions( lua_State* L,
const std::vector<lua_cpp::Reg>& functions)
111 luaL_checkversion(L);
113 if (l.name !=
nullptr) {
115 lua_setfield(L, -2, l.name);
129 lua_insert(L, -(1+nup));
133 void set_functions( lua_State* L,
const std::vector<lua_cpp::Reg>& functions,
int nup )
135 luaL_checkversion(L);
136 luaL_checkstack(L, nup+1,
"too many upvalues");
138 if (l.name ==
nullptr) {
142 for (
i = 0;
i < nup; ++
i)
143 lua_pushvalue(L, -nup);
145 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_tostring2(lua_State *L)
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.