Remove lua_State parameter from LuaError::LuaError

master
ShadowNinja 2014-03-15 16:28:59 -04:00
parent f8b7555558
commit 31fe72dbac
13 changed files with 39 additions and 52 deletions

View File

@ -654,7 +654,7 @@ ItemStack read_item(lua_State* L, int index,Server* srv)
} }
else else
{ {
throw LuaError(NULL, "Expecting itemstack, itemstring, table or nil"); throw LuaError("Expecting itemstack, itemstring, table or nil");
} }
} }
@ -941,7 +941,7 @@ std::vector<ItemStack> read_items(lua_State *L, int index, Server *srv)
while (lua_next(L, index)) { while (lua_next(L, index)) {
s32 key = luaL_checkinteger(L, -2); s32 key = luaL_checkinteger(L, -2);
if (key < 1) { if (key < 1) {
throw LuaError(NULL, "Invalid inventory list index"); throw LuaError("Invalid inventory list index");
} }
if (items.size() < (u32) key) { if (items.size() < (u32) key) {
items.resize(key); items.resize(key);

View File

@ -71,7 +71,7 @@ void script_error(lua_State *L)
{ {
const char *s = lua_tostring(L, -1); const char *s = lua_tostring(L, -1);
std::string str(s ? s : ""); std::string str(s ? s : "");
throw LuaError(NULL, str); throw LuaError(str);
} }
// Push the list of callbacks (a lua table). // Push the list of callbacks (a lua table).

View File

@ -23,13 +23,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "common/c_internal.h" #include "common/c_internal.h"
#include "itemdef.h" #include "itemdef.h"
LuaError::LuaError(lua_State *L, const std::string &s) :
ServerError(s)
{
if (L) {
m_s += '\n' + script_get_backtrace(L);
}
}
struct EnumString es_ItemType[] = struct EnumString es_ItemType[] =
{ {

View File

@ -55,14 +55,7 @@ public:
class LuaError : public ServerError class LuaError : public ServerError
{ {
public: public:
LuaError(lua_State *L, const std::string &s); LuaError(const std::string &s) : ServerError(s) {}
virtual ~LuaError() throw()
{}
virtual const char * what() const throw()
{
return m_s.c_str();
}
}; };

View File

@ -151,13 +151,14 @@ void ScriptApiBase::realityCheck()
if(top >= 30){ if(top >= 30){
dstream<<"Stack is over 30:"<<std::endl; dstream<<"Stack is over 30:"<<std::endl;
stackDump(dstream); stackDump(dstream);
throw LuaError(m_luastack, "Stack is over 30 (reality check)"); std::string traceback = script_get_backtrace(m_luastack);
throw LuaError("Stack is over 30 (reality check)\n" + traceback);
} }
} }
void ScriptApiBase::scriptError() void ScriptApiBase::scriptError()
{ {
throw LuaError(NULL, lua_tostring(m_luastack, -1)); throw LuaError(lua_tostring(m_luastack, -1));
} }
void ScriptApiBase::stackDump(std::ostream &o) void ScriptApiBase::stackDump(std::ostream &o)

View File

@ -54,7 +54,7 @@ int ScriptApiDetached::detached_inventory_AllowMove(
if(lua_pcall(L, 7, 1, errorhandler)) if(lua_pcall(L, 7, 1, errorhandler))
scriptError(); scriptError();
if(!lua_isnumber(L, -1)) if(!lua_isnumber(L, -1))
throw LuaError(NULL, "allow_move should return a number"); throw LuaError("allow_move should return a number");
int ret = luaL_checkinteger(L, -1); int ret = luaL_checkinteger(L, -1);
lua_pop(L, 2); // Pop integer and error handler lua_pop(L, 2); // Pop integer and error handler
return ret; return ret;
@ -86,7 +86,7 @@ int ScriptApiDetached::detached_inventory_AllowPut(
if(lua_pcall(L, 5, 1, errorhandler)) if(lua_pcall(L, 5, 1, errorhandler))
scriptError(); scriptError();
if(!lua_isnumber(L, -1)) if(!lua_isnumber(L, -1))
throw LuaError(NULL, "allow_put should return a number"); throw LuaError("allow_put should return a number");
int ret = luaL_checkinteger(L, -1); int ret = luaL_checkinteger(L, -1);
lua_pop(L, 2); // Pop integer and error handler lua_pop(L, 2); // Pop integer and error handler
return ret; return ret;
@ -118,7 +118,7 @@ int ScriptApiDetached::detached_inventory_AllowTake(
if(lua_pcall(L, 5, 1, errorhandler)) if(lua_pcall(L, 5, 1, errorhandler))
scriptError(); scriptError();
if(!lua_isnumber(L, -1)) if(!lua_isnumber(L, -1))
throw LuaError(NULL, "allow_take should return a number"); throw LuaError("allow_take should return a number");
int ret = luaL_checkinteger(L, -1); int ret = luaL_checkinteger(L, -1);
lua_pop(L, 2); // Pop integer and error handler lua_pop(L, 2); // Pop integer and error handler
return ret; return ret;

View File

@ -61,7 +61,7 @@ int ScriptApiNodemeta::nodemeta_inventory_AllowMove(v3s16 p,
scriptError(); scriptError();
lua_remove(L, errorhandler); // Remove error handler lua_remove(L, errorhandler); // Remove error handler
if(!lua_isnumber(L, -1)) if(!lua_isnumber(L, -1))
throw LuaError(NULL, "allow_metadata_inventory_move should" throw LuaError("allow_metadata_inventory_move should"
" return a number, guilty node: " + nodename); " return a number, guilty node: " + nodename);
int num = luaL_checkinteger(L, -1); int num = luaL_checkinteger(L, -1);
lua_pop(L, 1); // Pop integer lua_pop(L, 1); // Pop integer
@ -100,7 +100,7 @@ int ScriptApiNodemeta::nodemeta_inventory_AllowPut(v3s16 p,
scriptError(); scriptError();
lua_remove(L, errorhandler); // Remove error handler lua_remove(L, errorhandler); // Remove error handler
if(!lua_isnumber(L, -1)) if(!lua_isnumber(L, -1))
throw LuaError(NULL, "allow_metadata_inventory_put should" throw LuaError("allow_metadata_inventory_put should"
" return a number, guilty node: " + nodename); " return a number, guilty node: " + nodename);
int num = luaL_checkinteger(L, -1); int num = luaL_checkinteger(L, -1);
lua_pop(L, 1); // Pop integer lua_pop(L, 1); // Pop integer
@ -139,7 +139,7 @@ int ScriptApiNodemeta::nodemeta_inventory_AllowTake(v3s16 p,
scriptError(); scriptError();
lua_remove(L, errorhandler); // Remove error handler lua_remove(L, errorhandler); // Remove error handler
if(!lua_isnumber(L, -1)) if(!lua_isnumber(L, -1))
throw LuaError(NULL, "allow_metadata_inventory_take should" throw LuaError("allow_metadata_inventory_take should"
" return a number, guilty node: " + nodename); " return a number, guilty node: " + nodename);
int num = luaL_checkinteger(L, -1); int num = luaL_checkinteger(L, -1);
lua_pop(L, 1); // Pop integer lua_pop(L, 1); // Pop integer

View File

@ -33,7 +33,7 @@ bool ScriptApiServer::getAuth(const std::string &playername,
getAuthHandler(); getAuthHandler();
lua_getfield(L, -1, "get_auth"); lua_getfield(L, -1, "get_auth");
if(lua_type(L, -1) != LUA_TFUNCTION) if(lua_type(L, -1) != LUA_TFUNCTION)
throw LuaError(NULL, "Authentication handler missing get_auth"); throw LuaError("Authentication handler missing get_auth");
lua_pushstring(L, playername.c_str()); lua_pushstring(L, playername.c_str());
if(lua_pcall(L, 1, 1, errorhandler)) if(lua_pcall(L, 1, 1, errorhandler))
scriptError(); scriptError();
@ -48,13 +48,13 @@ bool ScriptApiServer::getAuth(const std::string &playername,
std::string password; std::string password;
bool found = getstringfield(L, -1, "password", password); bool found = getstringfield(L, -1, "password", password);
if(!found) if(!found)
throw LuaError(NULL, "Authentication handler didn't return password"); throw LuaError("Authentication handler didn't return password");
if(dst_password) if(dst_password)
*dst_password = password; *dst_password = password;
lua_getfield(L, -1, "privileges"); lua_getfield(L, -1, "privileges");
if(!lua_istable(L, -1)) if(!lua_istable(L, -1))
throw LuaError(NULL, "Authentication handler didn't return privilege table"); throw LuaError("Authentication handler didn't return privilege table");
if(dst_privs) if(dst_privs)
readPrivileges(-1, *dst_privs); readPrivileges(-1, *dst_privs);
lua_pop(L, 1); lua_pop(L, 1);
@ -74,7 +74,7 @@ void ScriptApiServer::getAuthHandler()
} }
lua_remove(L, -2); // Remove minetest lua_remove(L, -2); // Remove minetest
if(lua_type(L, -1) != LUA_TTABLE) if(lua_type(L, -1) != LUA_TTABLE)
throw LuaError(NULL, "Authentication handler table not valid"); throw LuaError("Authentication handler table not valid");
} }
void ScriptApiServer::readPrivileges(int index, std::set<std::string> &result) void ScriptApiServer::readPrivileges(int index, std::set<std::string> &result)
@ -108,7 +108,7 @@ void ScriptApiServer::createAuth(const std::string &playername,
lua_getfield(L, -1, "create_auth"); lua_getfield(L, -1, "create_auth");
lua_remove(L, -2); // Remove auth handler lua_remove(L, -2); // Remove auth handler
if(lua_type(L, -1) != LUA_TFUNCTION) if(lua_type(L, -1) != LUA_TFUNCTION)
throw LuaError(NULL, "Authentication handler missing create_auth"); throw LuaError("Authentication handler missing create_auth");
lua_pushstring(L, playername.c_str()); lua_pushstring(L, playername.c_str());
lua_pushstring(L, password.c_str()); lua_pushstring(L, password.c_str());
if(lua_pcall(L, 2, 0, errorhandler)) if(lua_pcall(L, 2, 0, errorhandler))
@ -128,7 +128,7 @@ bool ScriptApiServer::setPassword(const std::string &playername,
lua_getfield(L, -1, "set_password"); lua_getfield(L, -1, "set_password");
lua_remove(L, -2); // Remove auth handler lua_remove(L, -2); // Remove auth handler
if(lua_type(L, -1) != LUA_TFUNCTION) if(lua_type(L, -1) != LUA_TFUNCTION)
throw LuaError(NULL, "Authentication handler missing set_password"); throw LuaError("Authentication handler missing set_password");
lua_pushstring(L, playername.c_str()); lua_pushstring(L, playername.c_str());
lua_pushstring(L, password.c_str()); lua_pushstring(L, password.c_str());
if(lua_pcall(L, 2, 1, errorhandler)) if(lua_pcall(L, 2, 1, errorhandler))

View File

@ -48,7 +48,7 @@ protected:
ScriptApiBase *scriptIface = getScriptApiBase(L); ScriptApiBase *scriptIface = getScriptApiBase(L);
T *scriptIfaceDowncast = dynamic_cast<T*>(scriptIface); T *scriptIfaceDowncast = dynamic_cast<T*>(scriptIface);
if (!scriptIfaceDowncast) { if (!scriptIfaceDowncast) {
throw LuaError(NULL, "Requested unavailable ScriptApi - core engine bug!"); throw LuaError("Requested unavailable ScriptApi - core engine bug!");
} }
return scriptIfaceDowncast; return scriptIfaceDowncast;
} }

View File

@ -150,16 +150,16 @@ int ModApiCraft::l_register_craft(lua_State *L)
if(type == "shaped"){ if(type == "shaped"){
std::string output = getstringfield_default(L, table, "output", ""); std::string output = getstringfield_default(L, table, "output", "");
if(output == "") if(output == "")
throw LuaError(NULL, "Crafting definition is missing an output"); throw LuaError("Crafting definition is missing an output");
int width = 0; int width = 0;
std::vector<std::string> recipe; std::vector<std::string> recipe;
lua_getfield(L, table, "recipe"); lua_getfield(L, table, "recipe");
if(lua_isnil(L, -1)) if(lua_isnil(L, -1))
throw LuaError(NULL, "Crafting definition is missing a recipe" throw LuaError("Crafting definition is missing a recipe"
" (output=\"" + output + "\")"); " (output=\"" + output + "\")");
if(!readCraftRecipeShaped(L, -1, width, recipe)) if(!readCraftRecipeShaped(L, -1, width, recipe))
throw LuaError(NULL, "Invalid crafting recipe" throw LuaError("Invalid crafting recipe"
" (output=\"" + output + "\")"); " (output=\"" + output + "\")");
CraftReplacements replacements; CraftReplacements replacements;
@ -167,7 +167,7 @@ int ModApiCraft::l_register_craft(lua_State *L)
if(!lua_isnil(L, -1)) if(!lua_isnil(L, -1))
{ {
if(!readCraftReplacements(L, -1, replacements)) if(!readCraftReplacements(L, -1, replacements))
throw LuaError(NULL, "Invalid replacements" throw LuaError("Invalid replacements"
" (output=\"" + output + "\")"); " (output=\"" + output + "\")");
} }
@ -181,17 +181,17 @@ int ModApiCraft::l_register_craft(lua_State *L)
else if(type == "shapeless"){ else if(type == "shapeless"){
std::string output = getstringfield_default(L, table, "output", ""); std::string output = getstringfield_default(L, table, "output", "");
if(output == "") if(output == "")
throw LuaError(NULL, "Crafting definition (shapeless)" throw LuaError("Crafting definition (shapeless)"
" is missing an output"); " is missing an output");
std::vector<std::string> recipe; std::vector<std::string> recipe;
lua_getfield(L, table, "recipe"); lua_getfield(L, table, "recipe");
if(lua_isnil(L, -1)) if(lua_isnil(L, -1))
throw LuaError(NULL, "Crafting definition (shapeless)" throw LuaError("Crafting definition (shapeless)"
" is missing a recipe" " is missing a recipe"
" (output=\"" + output + "\")"); " (output=\"" + output + "\")");
if(!readCraftRecipeShapeless(L, -1, recipe)) if(!readCraftRecipeShapeless(L, -1, recipe))
throw LuaError(NULL, "Invalid crafting recipe" throw LuaError("Invalid crafting recipe"
" (output=\"" + output + "\")"); " (output=\"" + output + "\")");
CraftReplacements replacements; CraftReplacements replacements;
@ -199,7 +199,7 @@ int ModApiCraft::l_register_craft(lua_State *L)
if(!lua_isnil(L, -1)) if(!lua_isnil(L, -1))
{ {
if(!readCraftReplacements(L, -1, replacements)) if(!readCraftReplacements(L, -1, replacements))
throw LuaError(NULL, "Invalid replacements" throw LuaError("Invalid replacements"
" (output=\"" + output + "\")"); " (output=\"" + output + "\")");
} }
@ -224,12 +224,12 @@ int ModApiCraft::l_register_craft(lua_State *L)
else if(type == "cooking"){ else if(type == "cooking"){
std::string output = getstringfield_default(L, table, "output", ""); std::string output = getstringfield_default(L, table, "output", "");
if(output == "") if(output == "")
throw LuaError(NULL, "Crafting definition (cooking)" throw LuaError("Crafting definition (cooking)"
" is missing an output"); " is missing an output");
std::string recipe = getstringfield_default(L, table, "recipe", ""); std::string recipe = getstringfield_default(L, table, "recipe", "");
if(recipe == "") if(recipe == "")
throw LuaError(NULL, "Crafting definition (cooking)" throw LuaError("Crafting definition (cooking)"
" is missing a recipe" " is missing a recipe"
" (output=\"" + output + "\")"); " (output=\"" + output + "\")");
@ -240,7 +240,7 @@ int ModApiCraft::l_register_craft(lua_State *L)
if(!lua_isnil(L, -1)) if(!lua_isnil(L, -1))
{ {
if(!readCraftReplacements(L, -1, replacements)) if(!readCraftReplacements(L, -1, replacements))
throw LuaError(NULL, "Invalid replacements" throw LuaError("Invalid replacements"
" (cooking output=\"" + output + "\")"); " (cooking output=\"" + output + "\")");
} }
@ -254,7 +254,7 @@ int ModApiCraft::l_register_craft(lua_State *L)
else if(type == "fuel"){ else if(type == "fuel"){
std::string recipe = getstringfield_default(L, table, "recipe", ""); std::string recipe = getstringfield_default(L, table, "recipe", "");
if(recipe == "") if(recipe == "")
throw LuaError(NULL, "Crafting definition (fuel)" throw LuaError("Crafting definition (fuel)"
" is missing a recipe"); " is missing a recipe");
float burntime = getfloatfield_default(L, table, "burntime", 1.0); float burntime = getfloatfield_default(L, table, "burntime", 1.0);
@ -264,7 +264,7 @@ int ModApiCraft::l_register_craft(lua_State *L)
if(!lua_isnil(L, -1)) if(!lua_isnil(L, -1))
{ {
if(!readCraftReplacements(L, -1, replacements)) if(!readCraftReplacements(L, -1, replacements))
throw LuaError(NULL, "Invalid replacements" throw LuaError("Invalid replacements"
" (fuel recipe=\"" + recipe + "\")"); " (fuel recipe=\"" + recipe + "\")");
} }
@ -274,7 +274,7 @@ int ModApiCraft::l_register_craft(lua_State *L)
} }
else else
{ {
throw LuaError(NULL, "Unknown crafting definition type: \"" + type + "\""); throw LuaError("Unknown crafting definition type: \"" + type + "\"");
} }
lua_pop(L, 1); lua_pop(L, 1);

View File

@ -470,7 +470,7 @@ int ModApiItemMod::l_register_item_raw(lua_State *L)
name = lua_tostring(L, -1); name = lua_tostring(L, -1);
verbosestream<<"register_item_raw: "<<name<<std::endl; verbosestream<<"register_item_raw: "<<name<<std::endl;
} else { } else {
throw LuaError(NULL, "register_item_raw: name is not defined or not a string"); throw LuaError("register_item_raw: name is not defined or not a string");
} }
// Check if on_use is defined // Check if on_use is defined
@ -500,7 +500,7 @@ int ModApiItemMod::l_register_item_raw(lua_State *L)
content_t id = ndef->set(f.name, f); content_t id = ndef->set(f.name, f);
if(id > MAX_REGISTERED_CONTENT){ if(id > MAX_REGISTERED_CONTENT){
throw LuaError(NULL, "Number of registerable nodes (" throw LuaError("Number of registerable nodes ("
+ itos(MAX_REGISTERED_CONTENT+1) + itos(MAX_REGISTERED_CONTENT+1)
+ ") exceeded (" + name + ")"); + ") exceeded (" + name + ")");
} }

View File

@ -330,10 +330,10 @@ int LuaPseudoRandom::l_next(lua_State *L)
max = luaL_checkinteger(L, 3); max = luaL_checkinteger(L, 3);
if(max < min){ if(max < min){
errorstream<<"PseudoRandom.next(): max="<<max<<" min="<<min<<std::endl; errorstream<<"PseudoRandom.next(): max="<<max<<" min="<<min<<std::endl;
throw LuaError(NULL, "PseudoRandom.next(): max < min"); throw LuaError("PseudoRandom.next(): max < min");
} }
if(max - min != 32767 && max - min > 32767/5) if(max - min != 32767 && max - min > 32767/5)
throw LuaError(NULL, "PseudoRandom.next() max-min is not 32767" throw LuaError("PseudoRandom.next() max-min is not 32767"
" and is > 32768/5. This is disallowed due to" " and is > 32768/5. This is disallowed due to"
" the bad random distribution the" " the bad random distribution the"
" implementation would otherwise make."); " implementation would otherwise make.");

View File

@ -1120,7 +1120,7 @@ int ObjectRef::l_set_sky(lua_State *L)
} }
if (type == "skybox" && params.size() != 6) if (type == "skybox" && params.size() != 6)
throw LuaError(L, "skybox expects 6 textures"); throw LuaError("skybox expects 6 textures");
if (!getServer(L)->setSky(player, bgcolor, type, params)) if (!getServer(L)->setSky(player, bgcolor, type, params))
return 0; return 0;