1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Pass a errfunc to lua_pcall to get a traceback

This commit is contained in:
ShadowNinja 2013-11-05 12:06:15 -05:00
parent 3f519eb729
commit 371b39a09a
19 changed files with 424 additions and 324 deletions

View file

@ -871,6 +871,8 @@ void read_groups(lua_State *L, int index,
/******************************************************************************/
void push_items(lua_State *L, const std::vector<ItemStack> &items)
{
lua_pushcfunction(L, script_error_handler);
int errorhandler = lua_gettop(L);
// Get the table insert function
lua_getglobal(L, "table");
lua_getfield(L, -1, "insert");
@ -883,11 +885,12 @@ void push_items(lua_State *L, const std::vector<ItemStack> &items)
lua_pushvalue(L, table_insert);
lua_pushvalue(L, table);
LuaItemStack::create(L, item);
if(lua_pcall(L, 2, 0, 0))
script_error(L, "error: %s", lua_tostring(L, -1));
if(lua_pcall(L, 2, 0, errorhandler))
script_error(L);
}
lua_remove(L, -2); // Remove table
lua_remove(L, -2); // Remove insert
lua_remove(L, -2); // Remove table
lua_remove(L, -2); // Remove error handler
}
/******************************************************************************/