summaryrefslogtreecommitdiff
path: root/src/script
diff options
context:
space:
mode:
authorShadowNinja <shadowninja@minetest.net>2015-03-07 20:01:59 -0500
committerShadowNinja <shadowninja@minetest.net>2015-03-07 20:04:01 -0500
commitd75a0a73941259ea3ebac297803838094c7d458f (patch)
tree225f3e464385e53042a6b1dfa386f08015e9cd04 /src/script
parent86e9408c9fe07baf384386def1f0c68b2d0cc456 (diff)
downloadminetest-d75a0a73941259ea3ebac297803838094c7d458f.tar.gz
minetest-d75a0a73941259ea3ebac297803838094c7d458f.tar.bz2
minetest-d75a0a73941259ea3ebac297803838094c7d458f.zip
Don't use luaL_checkstring to read node names, it's only for arguments
This caused confusing error messages like "argument #4 to set_node is not a string."
Diffstat (limited to 'src/script')
-rw-r--r--src/script/common/c_content.cpp19
1 files changed, 10 insertions, 9 deletions
diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp
index ff9aee8ed..8bb22186b 100644
--- a/src/script/common/c_content.cpp
+++ b/src/script/common/c_content.cpp
@@ -546,22 +546,23 @@ NodeBox read_nodebox(lua_State *L, int index)
MapNode readnode(lua_State *L, int index, INodeDefManager *ndef)
{
lua_getfield(L, index, "name");
- const char *name = luaL_checkstring(L, -1);
+ if (!lua_isstring(L, -1))
+ throw LuaError("Node name is not set or is not a string!");
+ const char *name = lua_tostring(L, -1);
lua_pop(L, 1);
- u8 param1;
+
+ u8 param1 = 0;
lua_getfield(L, index, "param1");
- if(lua_isnil(L, -1))
- param1 = 0;
- else
+ if (!lua_isnil(L, -1))
param1 = lua_tonumber(L, -1);
lua_pop(L, 1);
- u8 param2;
+
+ u8 param2 = 0;
lua_getfield(L, index, "param2");
- if(lua_isnil(L, -1))
- param2 = 0;
- else
+ if (!lua_isnil(L, -1))
param2 = lua_tonumber(L, -1);
lua_pop(L, 1);
+
return MapNode(ndef, name, param1, param2);
}