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());
79 luaL_checktype(L, 1, LUA_TTHREAD);
83 lua_pushfstring(L,
"thread: %s", luaL_checkstring(L, -1));
89 luaL_checktype(L, 1, LUA_TLIGHTUSERDATA);
90 lua_pushstring(L,
"userdata: light");
98 lua_setfield(L, -2,
"__call");
100 lua_setfield(L, -2,
"__gc");
102 lua_setfield(L, -2,
"__tostring");
103 lua_pushstring(L,
"function");
104 lua_setfield(L, -2,
"__metatable");
105 lua_pushvalue(L, -1);
106 lua_setfield(L, -2,
"__index");
112 lua_createtable(L, 0, 1);
113 lua_pushvalue(L, -2);
114 lua_setfield(L, -2,
"__tostring");
115 lua_pushstring(L,
"function");
116 lua_setfield(L, -2,
"__metatable");
117 lua_setmetatable(L, -2);
120 lua_createtable(L, 0, 1);
122 lua_setfield(L, -2,
"__tostring");
123 lua_pushstring(L,
"thread");
124 lua_setfield(L, -2,
"__metatable");
125 lua_setmetatable(L, -2);
129 lua_pushlightuserdata(L,
nullptr);
130 lua_createtable(L, 0, 1);
132 lua_setfield(L, -2,
"__tostring");
133 lua_pushstring(L,
"userdata: light");
134 lua_setfield(L, -2,
"__metatable");
135 lua_setmetatable(L, -2);
146 void set_functions( lua_State* L,
const std::vector<lua_cpp::Reg>& functions)
148 luaL_checkversion(L);
150 if (l.name !=
nullptr) {
152 lua_setfield(L, -2, l.name);
166 lua_insert(L, -(1+nup));
170 void set_functions( lua_State* L,
const std::vector<lua_cpp::Reg>& functions,
int nup )
172 luaL_checkversion(L);
173 luaL_checkstack(L, nup+1,
"too many upvalues");
175 if (l.name ==
nullptr) {
179 for (
i = 0;
i < nup; ++
i)
180 lua_pushvalue(L, -nup);
182 lua_setfield(L, -(nup + 2), l.name);
Standard logging facilities (interface).
bool luaW_getglobal(lua_State *L, const std::vector< std::string > &path)
Pushes the value found by following the variadic names (char *), if the value is not nil.
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)
static int intf_light_userdata_tostring(lua_State *L)
char const * cpp_function
static int intf_thread_tostring(lua_State *L)
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.