From d274cbfce6ed39f5b7ad41261ede8c0fad7e980a Mon Sep 17 00:00:00 2001 From: kwolekr Date: Wed, 8 Oct 2014 15:28:14 -0400 Subject: Add NodeResolver and clean up node name -> content ID resolution system --- src/script/common/c_converter.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'src/script/common/c_converter.cpp') diff --git a/src/script/common/c_converter.cpp b/src/script/common/c_converter.cpp index b2ef0573c..a906171d3 100644 --- a/src/script/common/c_converter.cpp +++ b/src/script/common/c_converter.cpp @@ -227,6 +227,25 @@ std::vector read_aabb3f_vector(lua_State *L, int index, f32 scale) return boxes; } +bool read_stringlist(lua_State *L, int index, std::vector &result) +{ + if (index < 0) + index = lua_gettop(L) + 1 + index; + + if (lua_istable(L, index)) { + lua_pushnil(L); + while (lua_next(L, index)) { + result.push_back(lua_tostring(L, -1)); + lua_pop(L, 1); + } + } else if (lua_isstring(L, index)) { + result.push_back(lua_tostring(L, index)); + } else { + return false; + } + return true; +} + /* Table field getters */ @@ -287,6 +306,17 @@ bool getboolfield(lua_State *L, int table, return got; } +bool getstringlistfield(lua_State *L, int table, const char *fieldname, + std::vector &result) +{ + lua_getfield(L, table, fieldname); + + bool got = read_stringlist(L, -1, result); + + lua_pop(L, 1); + return got; +} + std::string checkstringfield(lua_State *L, int table, const char *fieldname) { -- cgit v1.2.3