diff options
author | kwolekr <kwolekr@minetest.net> | 2015-04-16 04:12:26 -0400 |
---|---|---|
committer | kwolekr <kwolekr@minetest.net> | 2015-04-16 16:27:05 -0400 |
commit | 479f38973e13680d6a39d9c2a7f29fd330b67d41 (patch) | |
tree | c6719cf37bfbc44f98cc33b9b2693542b8fdd8cc /src/script/common | |
parent | 0c634a97197d50f2ca58825f1b215d0407397ac6 (diff) | |
download | minetest-479f38973e13680d6a39d9c2a7f29fd330b67d41.tar.gz minetest-479f38973e13680d6a39d9c2a7f29fd330b67d41.tar.bz2 minetest-479f38973e13680d6a39d9c2a7f29fd330b67d41.zip |
Schematics: Refactor NodeResolver and add NodeResolveMethod
NodeResolver name lists now belong to the NodeResolver object instead of
the associated NodeDefManager. In addition to minimizing unnecessary
abstraction and overhead, this move permits NodeResolvers to look up nodes
that they had previously set pending for resolution. So far, this
functionality has been used in the case of schematics for
serialization/deserialization.
Diffstat (limited to 'src/script/common')
-rw-r--r-- | src/script/common/c_converter.cpp | 26 | ||||
-rw-r--r-- | src/script/common/c_converter.h | 8 |
2 files changed, 19 insertions, 15 deletions
diff --git a/src/script/common/c_converter.cpp b/src/script/common/c_converter.cpp index 66eeec68e..5070dca2d 100644 --- a/src/script/common/c_converter.cpp +++ b/src/script/common/c_converter.cpp @@ -227,24 +227,28 @@ std::vector<aabb3f> read_aabb3f_vector(lua_State *L, int index, f32 scale) return boxes; } -bool read_stringlist(lua_State *L, int index, std::vector<const char *> &result) +size_t read_stringlist(lua_State *L, int index, std::vector<std::string> *result) { if (index < 0) index = lua_gettop(L) + 1 + index; + size_t num_strings = 0; + if (lua_istable(L, index)) { lua_pushnil(L); while (lua_next(L, index)) { - if (lua_isstring(L, -1)) - result.push_back(lua_tostring(L, -1)); + if (lua_isstring(L, -1)) { + result->push_back(lua_tostring(L, -1)); + num_strings++; + } lua_pop(L, 1); } } else if (lua_isstring(L, index)) { - result.push_back(lua_tostring(L, index)); - } else { - return false; + result->push_back(lua_tostring(L, index)); + num_strings++; } - return true; + + return num_strings; } /* @@ -307,15 +311,15 @@ bool getboolfield(lua_State *L, int table, return got; } -bool getstringlistfield(lua_State *L, int table, const char *fieldname, - std::vector<const char *> &result) +size_t getstringlistfield(lua_State *L, int table, const char *fieldname, + std::vector<std::string> *result) { lua_getfield(L, table, fieldname); - bool got = read_stringlist(L, -1, result); + size_t num_strings_read = read_stringlist(L, -1, result); lua_pop(L, 1); - return got; + return num_strings_read; } std::string checkstringfield(lua_State *L, int table, diff --git a/src/script/common/c_converter.h b/src/script/common/c_converter.h index 3b7eb6f7d..fdcd0c8fc 100644 --- a/src/script/common/c_converter.h +++ b/src/script/common/c_converter.h @@ -48,9 +48,9 @@ int getintfield_default (lua_State *L, int table, bool getstringfield(lua_State *L, int table, const char *fieldname, std::string &result); -bool getstringlistfield(lua_State *L, int table, +size_t getstringlistfield(lua_State *L, int table, const char *fieldname, - std::vector<const char *> &result); + std::vector<std::string> *result); bool getintfield(lua_State *L, int table, const char *fieldname, int &result); void read_groups(lua_State *L, int index, @@ -83,8 +83,8 @@ video::SColor readARGB8 (lua_State *L, int index); aabb3f read_aabb3f (lua_State *L, int index, f32 scale); v3s16 read_v3s16 (lua_State *L, int index); std::vector<aabb3f> read_aabb3f_vector (lua_State *L, int index, f32 scale); -bool read_stringlist (lua_State *L, int index, - std::vector<const char *> &result); +size_t read_stringlist (lua_State *L, int index, + std::vector<std::string> *result); void push_v3s16 (lua_State *L, v3s16 p); void pushFloatPos (lua_State *L, v3f p); |