aboutsummaryrefslogtreecommitdiff
path: root/src/script/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/script/common')
-rw-r--r--src/script/common/c_converter.cpp30
-rw-r--r--src/script/common/c_converter.h42
2 files changed, 53 insertions, 19 deletions
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<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)
+{
+ 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<const char *> &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)
{
diff --git a/src/script/common/c_converter.h b/src/script/common/c_converter.h
index 0c051a803..3b7eb6f7d 100644
--- a/src/script/common/c_converter.h
+++ b/src/script/common/c_converter.h
@@ -37,7 +37,7 @@ extern "C" {
#include <lua.h>
}
-std::string getstringfield_default (lua_State *L, int table,
+std::string getstringfield_default(lua_State *L, int table,
const char *fieldname, const std::string &default_);
bool getboolfield_default(lua_State *L, int table,
const char *fieldname, bool default_);
@@ -48,9 +48,12 @@ 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,
+ const char *fieldname,
+ std::vector<const char *> &result);
bool getintfield(lua_State *L, int table,
const char *fieldname, int &result);
-void read_groups (lua_State *L, int index,
+void read_groups(lua_State *L, int index,
std::map<std::string, int> &result);
bool getboolfield(lua_State *L, int table,
const char *fieldname, bool &result);
@@ -68,28 +71,29 @@ void setboolfield(lua_State *L, int table,
const char *fieldname, bool value);
-v3f checkFloatPos (lua_State *L, int index);
-v3f check_v3f (lua_State *L, int index);
-v3s16 check_v3s16 (lua_State *L, int index);
+v3f checkFloatPos (lua_State *L, int index);
+v3f check_v3f (lua_State *L, int index);
+v3s16 check_v3s16 (lua_State *L, int index);
-v3f read_v3f (lua_State *L, int index);
-v2f read_v2f (lua_State *L, int index);
-v2s16 read_v2s16 (lua_State *L, int index);
-v2s32 read_v2s32 (lua_State *L, int index);
-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);
+v3f read_v3f (lua_State *L, int index);
+v2f read_v2f (lua_State *L, int index);
+v2s16 read_v2s16 (lua_State *L, int index);
+v2s32 read_v2s32 (lua_State *L, int index);
+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);
-void push_v3s16 (lua_State *L, v3s16 p);
-void pushFloatPos (lua_State *L, v3f p);
-void push_v3f (lua_State *L, v3f p);
-void push_v2f (lua_State *L, v2f p);
+void push_v3s16 (lua_State *L, v3s16 p);
+void pushFloatPos (lua_State *L, v3f p);
+void push_v3f (lua_State *L, v3f p);
+void push_v2f (lua_State *L, v2f p);
-void warn_if_field_exists (lua_State *L,
+void warn_if_field_exists (lua_State *L,
int table,
const char *fieldname,
const std::string &message);