aboutsummaryrefslogtreecommitdiff
path: root/src/script/lua_api
diff options
context:
space:
mode:
Diffstat (limited to 'src/script/lua_api')
-rw-r--r--src/script/lua_api/l_base.h1
-rw-r--r--src/script/lua_api/l_craft.cpp2
-rw-r--r--src/script/lua_api/l_env.cpp28
-rw-r--r--src/script/lua_api/l_noise.cpp5
-rw-r--r--src/script/lua_api/l_rollback.cpp2
-rw-r--r--src/script/lua_api/l_server.cpp3
6 files changed, 29 insertions, 12 deletions
diff --git a/src/script/lua_api/l_base.h b/src/script/lua_api/l_base.h
index 71ebd215c..808043bd4 100644
--- a/src/script/lua_api/l_base.h
+++ b/src/script/lua_api/l_base.h
@@ -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>
diff --git a/src/script/lua_api/l_craft.cpp b/src/script/lua_api/l_craft.cpp
index b0a47bfc1..c5732bad2 100644
--- a/src/script/lua_api/l_craft.cpp
+++ b/src/script/lua_api/l_craft.cpp
@@ -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;
diff --git a/src/script/lua_api/l_env.cpp b/src/script/lua_api/l_env.cpp
index 436eb014d..9bed23d47 100644
--- a/src/script/lua_api/l_env.cpp
+++ b/src/script/lua_api/l_env.cpp
@@ -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;
diff --git a/src/script/lua_api/l_noise.cpp b/src/script/lua_api/l_noise.cpp
index ecbda9fad..4b0c7932d 100644
--- a/src/script/lua_api/l_noise.cpp
+++ b/src/script/lua_api/l_noise.cpp
@@ -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;
diff --git a/src/script/lua_api/l_rollback.cpp b/src/script/lua_api/l_rollback.cpp
index 6076399ae..d5abe176e 100644
--- a/src/script/lua_api/l_rollback.cpp
+++ b/src/script/lua_api/l_rollback.cpp
@@ -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
diff --git a/src/script/lua_api/l_server.cpp b/src/script/lua_api/l_server.cpp
index 8e809c36a..19e2f1bcb 100644
--- a/src/script/lua_api/l_server.cpp
+++ b/src/script/lua_api/l_server.cpp
@@ -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;
}