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:
parent
3f519eb729
commit
371b39a09a
19 changed files with 424 additions and 324 deletions
|
@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#define L_BASE_H_
|
||||
|
||||
#include "common/c_types.h"
|
||||
#include "common/c_internal.h"
|
||||
|
||||
extern "C" {
|
||||
#include <lua.h>
|
||||
|
|
|
@ -449,7 +449,7 @@ int ModApiCraft::l_get_all_craft_recipes(lua_State *L)
|
|||
lua_pushstring(L, &tmpout.item[0]);
|
||||
lua_setfield(L, -2, "output");
|
||||
if (lua_pcall(L, 2, 0, 0))
|
||||
script_error(L, "error: %s", lua_tostring(L, -1));
|
||||
script_error(L);
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
|
|
|
@ -53,28 +53,34 @@ void LuaABM::trigger(ServerEnvironment *env, v3s16 p, MapNode n,
|
|||
assert(lua_checkstack(L, 20));
|
||||
StackUnroller stack_unroller(L);
|
||||
|
||||
lua_pushcfunction(L, script_error_handler);
|
||||
int errorhandler = lua_gettop(L);
|
||||
|
||||
// Get minetest.registered_abms
|
||||
lua_getglobal(L, "minetest");
|
||||
lua_getfield(L, -1, "registered_abms");
|
||||
luaL_checktype(L, -1, LUA_TTABLE);
|
||||
int registered_abms = lua_gettop(L);
|
||||
lua_remove(L, -2); // Remove "minetest"
|
||||
|
||||
// Get minetest.registered_abms[m_id]
|
||||
lua_pushnumber(L, m_id);
|
||||
lua_gettable(L, registered_abms);
|
||||
lua_gettable(L, -2);
|
||||
if(lua_isnil(L, -1))
|
||||
assert(0);
|
||||
lua_remove(L, -2); // Remove "registered_abms"
|
||||
|
||||
// Call action
|
||||
luaL_checktype(L, -1, LUA_TTABLE);
|
||||
lua_getfield(L, -1, "action");
|
||||
luaL_checktype(L, -1, LUA_TFUNCTION);
|
||||
lua_remove(L, -2); // Remove "registered_abms[m_id]"
|
||||
push_v3s16(L, p);
|
||||
pushnode(L, n, env->getGameDef()->ndef());
|
||||
lua_pushnumber(L, active_object_count);
|
||||
lua_pushnumber(L, active_object_count_wider);
|
||||
if(lua_pcall(L, 4, 0, 0))
|
||||
script_error(L, "error: %s", lua_tostring(L, -1));
|
||||
if(lua_pcall(L, 4, 0, errorhandler))
|
||||
script_error(L);
|
||||
lua_pop(L, 1); // Pop error handler
|
||||
}
|
||||
|
||||
// Exported functions
|
||||
|
@ -370,15 +376,21 @@ int ModApiEnvMod::l_add_item(lua_State *L)
|
|||
ItemStack item = read_item(L, 2,getServer(L));
|
||||
if(item.empty() || !item.isKnown(getServer(L)->idef()))
|
||||
return 0;
|
||||
|
||||
lua_pushcfunction(L, script_error_handler);
|
||||
int errorhandler = lua_gettop(L);
|
||||
|
||||
// Use minetest.spawn_item to spawn a __builtin:item
|
||||
lua_getglobal(L, "minetest");
|
||||
lua_getfield(L, -1, "spawn_item");
|
||||
lua_remove(L, -2); // Remove minetest
|
||||
if(lua_isnil(L, -1))
|
||||
return 0;
|
||||
lua_pushvalue(L, 1);
|
||||
lua_pushstring(L, item.getItemString().c_str());
|
||||
if(lua_pcall(L, 2, 1, 0))
|
||||
script_error(L, "error: %s", lua_tostring(L, -1));
|
||||
if(lua_pcall(L, 2, 1, errorhandler))
|
||||
script_error(L);
|
||||
lua_remove(L, errorhandler); // Remove error handler
|
||||
return 1;
|
||||
/*lua_pushvalue(L, 1);
|
||||
lua_pushstring(L, "__builtin:item");
|
||||
|
@ -441,7 +453,7 @@ int ModApiEnvMod::l_get_objects_inside_radius(lua_State *L)
|
|||
lua_pushvalue(L, table);
|
||||
getScriptApiBase(L)->objectrefGetOrCreate(obj);
|
||||
if(lua_pcall(L, 2, 0, 0))
|
||||
script_error(L, "error: %s", lua_tostring(L, -1));
|
||||
script_error(L);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
@ -569,7 +581,7 @@ int ModApiEnvMod::l_find_nodes_in_area(lua_State *L)
|
|||
lua_pushvalue(L, table);
|
||||
push_v3s16(L, p);
|
||||
if(lua_pcall(L, 2, 0, 0))
|
||||
script_error(L, "error: %s", lua_tostring(L, -1));
|
||||
script_error(L);
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
|
|
|
@ -333,7 +333,10 @@ int LuaPseudoRandom::l_next(lua_State *L)
|
|||
throw LuaError(L, "PseudoRandom.next(): max < min");
|
||||
}
|
||||
if(max - min != 32767 && max - min > 32767/5)
|
||||
throw LuaError(L, "PseudoRandom.next() max-min is not 32767 and is > 32768/5. This is disallowed due to the bad random distribution the implementation would otherwise make.");
|
||||
throw LuaError(L, "PseudoRandom.next() max-min is not 32767"
|
||||
" and is > 32768/5. This is disallowed due to"
|
||||
" the bad random distribution the"
|
||||
" implementation would otherwise make.");
|
||||
PseudoRandom &pseudo = o->m_pseudo;
|
||||
int val = pseudo.next();
|
||||
val = (val % (max-min+1)) + min;
|
||||
|
|
|
@ -66,7 +66,7 @@ int ModApiRollback::l_rollback_revert_actions_by(lua_State *L)
|
|||
lua_pushvalue(L, table);
|
||||
lua_pushstring(L, i->c_str());
|
||||
if(lua_pcall(L, 2, 0, 0))
|
||||
script_error(L, "error: %s", lua_tostring(L, -1));
|
||||
script_error(L);
|
||||
}
|
||||
lua_remove(L, -2); // Remove table
|
||||
lua_remove(L, -2); // Remove insert
|
||||
|
|
|
@ -220,6 +220,7 @@ int ModApiServer::l_get_modpath(lua_State *L)
|
|||
int ModApiServer::l_get_modnames(lua_State *L)
|
||||
{
|
||||
NO_MAP_LOCK_REQUIRED;
|
||||
|
||||
// Get a list of mods
|
||||
std::list<std::string> mods_unsorted, mods_sorted;
|
||||
getServer(L)->getModNames(mods_unsorted);
|
||||
|
@ -263,7 +264,7 @@ int ModApiServer::l_get_modnames(lua_State *L)
|
|||
lua_pushstring(L, (*i).c_str());
|
||||
if(lua_pcall(L, 2, 0, 0) != 0)
|
||||
{
|
||||
script_error(L, "error: %s", lua_tostring(L, -1));
|
||||
script_error(L);
|
||||
}
|
||||
++i;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue