Skip to content

Commit 31fe72d

Browse files
committedMar 15, 2014
Remove lua_State parameter from LuaError::LuaError
1 parent f8b7555 commit 31fe72d

13 files changed

+39
-52
lines changed
 

‎src/script/common/c_content.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ ItemStack read_item(lua_State* L, int index,Server* srv)
654654
}
655655
else
656656
{
657-
throw LuaError(NULL, "Expecting itemstack, itemstring, table or nil");
657+
throw LuaError("Expecting itemstack, itemstring, table or nil");
658658
}
659659
}
660660

@@ -941,7 +941,7 @@ std::vector<ItemStack> read_items(lua_State *L, int index, Server *srv)
941941
while (lua_next(L, index)) {
942942
s32 key = luaL_checkinteger(L, -2);
943943
if (key < 1) {
944-
throw LuaError(NULL, "Invalid inventory list index");
944+
throw LuaError("Invalid inventory list index");
945945
}
946946
if (items.size() < (u32) key) {
947947
items.resize(key);

‎src/script/common/c_internal.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ void script_error(lua_State *L)
7171
{
7272
const char *s = lua_tostring(L, -1);
7373
std::string str(s ? s : "");
74-
throw LuaError(NULL, str);
74+
throw LuaError(str);
7575
}
7676

7777
// Push the list of callbacks (a lua table).

‎src/script/common/c_types.cpp

-7
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2323
#include "common/c_internal.h"
2424
#include "itemdef.h"
2525

26-
LuaError::LuaError(lua_State *L, const std::string &s) :
27-
ServerError(s)
28-
{
29-
if (L) {
30-
m_s += '\n' + script_get_backtrace(L);
31-
}
32-
}
3326

3427
struct EnumString es_ItemType[] =
3528
{

‎src/script/common/c_types.h

+1-8
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,7 @@ class StackUnroller
5555
class LuaError : public ServerError
5656
{
5757
public:
58-
LuaError(lua_State *L, const std::string &s);
59-
60-
virtual ~LuaError() throw()
61-
{}
62-
virtual const char * what() const throw()
63-
{
64-
return m_s.c_str();
65-
}
58+
LuaError(const std::string &s) : ServerError(s) {}
6659
};
6760

6861

‎src/script/cpp_api/s_base.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,14 @@ void ScriptApiBase::realityCheck()
151151
if(top >= 30){
152152
dstream<<"Stack is over 30:"<<std::endl;
153153
stackDump(dstream);
154-
throw LuaError(m_luastack, "Stack is over 30 (reality check)");
154+
std::string traceback = script_get_backtrace(m_luastack);
155+
throw LuaError("Stack is over 30 (reality check)\n" + traceback);
155156
}
156157
}
157158

158159
void ScriptApiBase::scriptError()
159160
{
160-
throw LuaError(NULL, lua_tostring(m_luastack, -1));
161+
throw LuaError(lua_tostring(m_luastack, -1));
161162
}
162163

163164
void ScriptApiBase::stackDump(std::ostream &o)

‎src/script/cpp_api/s_inventory.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ int ScriptApiDetached::detached_inventory_AllowMove(
5454
if(lua_pcall(L, 7, 1, errorhandler))
5555
scriptError();
5656
if(!lua_isnumber(L, -1))
57-
throw LuaError(NULL, "allow_move should return a number");
57+
throw LuaError("allow_move should return a number");
5858
int ret = luaL_checkinteger(L, -1);
5959
lua_pop(L, 2); // Pop integer and error handler
6060
return ret;
@@ -86,7 +86,7 @@ int ScriptApiDetached::detached_inventory_AllowPut(
8686
if(lua_pcall(L, 5, 1, errorhandler))
8787
scriptError();
8888
if(!lua_isnumber(L, -1))
89-
throw LuaError(NULL, "allow_put should return a number");
89+
throw LuaError("allow_put should return a number");
9090
int ret = luaL_checkinteger(L, -1);
9191
lua_pop(L, 2); // Pop integer and error handler
9292
return ret;
@@ -118,7 +118,7 @@ int ScriptApiDetached::detached_inventory_AllowTake(
118118
if(lua_pcall(L, 5, 1, errorhandler))
119119
scriptError();
120120
if(!lua_isnumber(L, -1))
121-
throw LuaError(NULL, "allow_take should return a number");
121+
throw LuaError("allow_take should return a number");
122122
int ret = luaL_checkinteger(L, -1);
123123
lua_pop(L, 2); // Pop integer and error handler
124124
return ret;

‎src/script/cpp_api/s_nodemeta.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ int ScriptApiNodemeta::nodemeta_inventory_AllowMove(v3s16 p,
6161
scriptError();
6262
lua_remove(L, errorhandler); // Remove error handler
6363
if(!lua_isnumber(L, -1))
64-
throw LuaError(NULL, "allow_metadata_inventory_move should"
64+
throw LuaError("allow_metadata_inventory_move should"
6565
" return a number, guilty node: " + nodename);
6666
int num = luaL_checkinteger(L, -1);
6767
lua_pop(L, 1); // Pop integer
@@ -100,7 +100,7 @@ int ScriptApiNodemeta::nodemeta_inventory_AllowPut(v3s16 p,
100100
scriptError();
101101
lua_remove(L, errorhandler); // Remove error handler
102102
if(!lua_isnumber(L, -1))
103-
throw LuaError(NULL, "allow_metadata_inventory_put should"
103+
throw LuaError("allow_metadata_inventory_put should"
104104
" return a number, guilty node: " + nodename);
105105
int num = luaL_checkinteger(L, -1);
106106
lua_pop(L, 1); // Pop integer
@@ -139,7 +139,7 @@ int ScriptApiNodemeta::nodemeta_inventory_AllowTake(v3s16 p,
139139
scriptError();
140140
lua_remove(L, errorhandler); // Remove error handler
141141
if(!lua_isnumber(L, -1))
142-
throw LuaError(NULL, "allow_metadata_inventory_take should"
142+
throw LuaError("allow_metadata_inventory_take should"
143143
" return a number, guilty node: " + nodename);
144144
int num = luaL_checkinteger(L, -1);
145145
lua_pop(L, 1); // Pop integer

‎src/script/cpp_api/s_server.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ bool ScriptApiServer::getAuth(const std::string &playername,
3333
getAuthHandler();
3434
lua_getfield(L, -1, "get_auth");
3535
if(lua_type(L, -1) != LUA_TFUNCTION)
36-
throw LuaError(NULL, "Authentication handler missing get_auth");
36+
throw LuaError("Authentication handler missing get_auth");
3737
lua_pushstring(L, playername.c_str());
3838
if(lua_pcall(L, 1, 1, errorhandler))
3939
scriptError();
@@ -48,13 +48,13 @@ bool ScriptApiServer::getAuth(const std::string &playername,
4848
std::string password;
4949
bool found = getstringfield(L, -1, "password", password);
5050
if(!found)
51-
throw LuaError(NULL, "Authentication handler didn't return password");
51+
throw LuaError("Authentication handler didn't return password");
5252
if(dst_password)
5353
*dst_password = password;
5454

5555
lua_getfield(L, -1, "privileges");
5656
if(!lua_istable(L, -1))
57-
throw LuaError(NULL, "Authentication handler didn't return privilege table");
57+
throw LuaError("Authentication handler didn't return privilege table");
5858
if(dst_privs)
5959
readPrivileges(-1, *dst_privs);
6060
lua_pop(L, 1);
@@ -74,7 +74,7 @@ void ScriptApiServer::getAuthHandler()
7474
}
7575
lua_remove(L, -2); // Remove minetest
7676
if(lua_type(L, -1) != LUA_TTABLE)
77-
throw LuaError(NULL, "Authentication handler table not valid");
77+
throw LuaError("Authentication handler table not valid");
7878
}
7979

8080
void ScriptApiServer::readPrivileges(int index, std::set<std::string> &result)
@@ -108,7 +108,7 @@ void ScriptApiServer::createAuth(const std::string &playername,
108108
lua_getfield(L, -1, "create_auth");
109109
lua_remove(L, -2); // Remove auth handler
110110
if(lua_type(L, -1) != LUA_TFUNCTION)
111-
throw LuaError(NULL, "Authentication handler missing create_auth");
111+
throw LuaError("Authentication handler missing create_auth");
112112
lua_pushstring(L, playername.c_str());
113113
lua_pushstring(L, password.c_str());
114114
if(lua_pcall(L, 2, 0, errorhandler))
@@ -128,7 +128,7 @@ bool ScriptApiServer::setPassword(const std::string &playername,
128128
lua_getfield(L, -1, "set_password");
129129
lua_remove(L, -2); // Remove auth handler
130130
if(lua_type(L, -1) != LUA_TFUNCTION)
131-
throw LuaError(NULL, "Authentication handler missing set_password");
131+
throw LuaError("Authentication handler missing set_password");
132132
lua_pushstring(L, playername.c_str());
133133
lua_pushstring(L, password.c_str());
134134
if(lua_pcall(L, 2, 1, errorhandler))

‎src/script/lua_api/l_base.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class ModApiBase {
4848
ScriptApiBase *scriptIface = getScriptApiBase(L);
4949
T *scriptIfaceDowncast = dynamic_cast<T*>(scriptIface);
5050
if (!scriptIfaceDowncast) {
51-
throw LuaError(NULL, "Requested unavailable ScriptApi - core engine bug!");
51+
throw LuaError("Requested unavailable ScriptApi - core engine bug!");
5252
}
5353
return scriptIfaceDowncast;
5454
}

‎src/script/lua_api/l_craft.cpp

+14-14
Original file line numberDiff line numberDiff line change
@@ -150,24 +150,24 @@ int ModApiCraft::l_register_craft(lua_State *L)
150150
if(type == "shaped"){
151151
std::string output = getstringfield_default(L, table, "output", "");
152152
if(output == "")
153-
throw LuaError(NULL, "Crafting definition is missing an output");
153+
throw LuaError("Crafting definition is missing an output");
154154

155155
int width = 0;
156156
std::vector<std::string> recipe;
157157
lua_getfield(L, table, "recipe");
158158
if(lua_isnil(L, -1))
159-
throw LuaError(NULL, "Crafting definition is missing a recipe"
159+
throw LuaError("Crafting definition is missing a recipe"
160160
" (output=\"" + output + "\")");
161161
if(!readCraftRecipeShaped(L, -1, width, recipe))
162-
throw LuaError(NULL, "Invalid crafting recipe"
162+
throw LuaError("Invalid crafting recipe"
163163
" (output=\"" + output + "\")");
164164

165165
CraftReplacements replacements;
166166
lua_getfield(L, table, "replacements");
167167
if(!lua_isnil(L, -1))
168168
{
169169
if(!readCraftReplacements(L, -1, replacements))
170-
throw LuaError(NULL, "Invalid replacements"
170+
throw LuaError("Invalid replacements"
171171
" (output=\"" + output + "\")");
172172
}
173173

@@ -181,25 +181,25 @@ int ModApiCraft::l_register_craft(lua_State *L)
181181
else if(type == "shapeless"){
182182
std::string output = getstringfield_default(L, table, "output", "");
183183
if(output == "")
184-
throw LuaError(NULL, "Crafting definition (shapeless)"
184+
throw LuaError("Crafting definition (shapeless)"
185185
" is missing an output");
186186

187187
std::vector<std::string> recipe;
188188
lua_getfield(L, table, "recipe");
189189
if(lua_isnil(L, -1))
190-
throw LuaError(NULL, "Crafting definition (shapeless)"
190+
throw LuaError("Crafting definition (shapeless)"
191191
" is missing a recipe"
192192
" (output=\"" + output + "\")");
193193
if(!readCraftRecipeShapeless(L, -1, recipe))
194-
throw LuaError(NULL, "Invalid crafting recipe"
194+
throw LuaError("Invalid crafting recipe"
195195
" (output=\"" + output + "\")");
196196

197197
CraftReplacements replacements;
198198
lua_getfield(L, table, "replacements");
199199
if(!lua_isnil(L, -1))
200200
{
201201
if(!readCraftReplacements(L, -1, replacements))
202-
throw LuaError(NULL, "Invalid replacements"
202+
throw LuaError("Invalid replacements"
203203
" (output=\"" + output + "\")");
204204
}
205205

@@ -224,12 +224,12 @@ int ModApiCraft::l_register_craft(lua_State *L)
224224
else if(type == "cooking"){
225225
std::string output = getstringfield_default(L, table, "output", "");
226226
if(output == "")
227-
throw LuaError(NULL, "Crafting definition (cooking)"
227+
throw LuaError("Crafting definition (cooking)"
228228
" is missing an output");
229229

230230
std::string recipe = getstringfield_default(L, table, "recipe", "");
231231
if(recipe == "")
232-
throw LuaError(NULL, "Crafting definition (cooking)"
232+
throw LuaError("Crafting definition (cooking)"
233233
" is missing a recipe"
234234
" (output=\"" + output + "\")");
235235

@@ -240,7 +240,7 @@ int ModApiCraft::l_register_craft(lua_State *L)
240240
if(!lua_isnil(L, -1))
241241
{
242242
if(!readCraftReplacements(L, -1, replacements))
243-
throw LuaError(NULL, "Invalid replacements"
243+
throw LuaError("Invalid replacements"
244244
" (cooking output=\"" + output + "\")");
245245
}
246246

@@ -254,7 +254,7 @@ int ModApiCraft::l_register_craft(lua_State *L)
254254
else if(type == "fuel"){
255255
std::string recipe = getstringfield_default(L, table, "recipe", "");
256256
if(recipe == "")
257-
throw LuaError(NULL, "Crafting definition (fuel)"
257+
throw LuaError("Crafting definition (fuel)"
258258
" is missing a recipe");
259259

260260
float burntime = getfloatfield_default(L, table, "burntime", 1.0);
@@ -264,7 +264,7 @@ int ModApiCraft::l_register_craft(lua_State *L)
264264
if(!lua_isnil(L, -1))
265265
{
266266
if(!readCraftReplacements(L, -1, replacements))
267-
throw LuaError(NULL, "Invalid replacements"
267+
throw LuaError("Invalid replacements"
268268
" (fuel recipe=\"" + recipe + "\")");
269269
}
270270

@@ -274,7 +274,7 @@ int ModApiCraft::l_register_craft(lua_State *L)
274274
}
275275
else
276276
{
277-
throw LuaError(NULL, "Unknown crafting definition type: \"" + type + "\"");
277+
throw LuaError("Unknown crafting definition type: \"" + type + "\"");
278278
}
279279

280280
lua_pop(L, 1);

‎src/script/lua_api/l_item.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ int ModApiItemMod::l_register_item_raw(lua_State *L)
470470
name = lua_tostring(L, -1);
471471
verbosestream<<"register_item_raw: "<<name<<std::endl;
472472
} else {
473-
throw LuaError(NULL, "register_item_raw: name is not defined or not a string");
473+
throw LuaError("register_item_raw: name is not defined or not a string");
474474
}
475475

476476
// Check if on_use is defined
@@ -500,7 +500,7 @@ int ModApiItemMod::l_register_item_raw(lua_State *L)
500500
content_t id = ndef->set(f.name, f);
501501

502502
if(id > MAX_REGISTERED_CONTENT){
503-
throw LuaError(NULL, "Number of registerable nodes ("
503+
throw LuaError("Number of registerable nodes ("
504504
+ itos(MAX_REGISTERED_CONTENT+1)
505505
+ ") exceeded (" + name + ")");
506506
}

‎src/script/lua_api/l_noise.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -330,10 +330,10 @@ int LuaPseudoRandom::l_next(lua_State *L)
330330
max = luaL_checkinteger(L, 3);
331331
if(max < min){
332332
errorstream<<"PseudoRandom.next(): max="<<max<<" min="<<min<<std::endl;
333-
throw LuaError(NULL, "PseudoRandom.next(): max < min");
333+
throw LuaError("PseudoRandom.next(): max < min");
334334
}
335335
if(max - min != 32767 && max - min > 32767/5)
336-
throw LuaError(NULL, "PseudoRandom.next() max-min is not 32767"
336+
throw LuaError("PseudoRandom.next() max-min is not 32767"
337337
" and is > 32768/5. This is disallowed due to"
338338
" the bad random distribution the"
339339
" implementation would otherwise make.");

‎src/script/lua_api/l_object.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1120,7 +1120,7 @@ int ObjectRef::l_set_sky(lua_State *L)
11201120
}
11211121

11221122
if (type == "skybox" && params.size() != 6)
1123-
throw LuaError(L, "skybox expects 6 textures");
1123+
throw LuaError("skybox expects 6 textures");
11241124

11251125
if (!getServer(L)->setSky(player, bgcolor, type, params))
11261126
return 0;

0 commit comments

Comments
 (0)
Please sign in to comment.