@@ -42,31 +42,51 @@ bool getboolfield_default(lua_State *L, int table,
42
42
const char *fieldname, bool default_);
43
43
float getfloatfield_default (lua_State *L, int table,
44
44
const char *fieldname, float default_);
45
- int getintfield_default (lua_State *L, int table,
45
+ int getintfield_default (lua_State *L, int table,
46
46
const char *fieldname, int default_);
47
47
48
+ template <typename T>
49
+ bool getintfield (lua_State *L, int table,
50
+ const char *fieldname, T &result)
51
+ {
52
+ lua_getfield (L, table, fieldname);
53
+ bool got = false ;
54
+ if (lua_isnumber (L, -1 )){
55
+ result = lua_tointeger (L, -1 );
56
+ got = true ;
57
+ }
58
+ lua_pop (L, 1 );
59
+ return got;
60
+ }
61
+
62
+ template <class T >
63
+ bool getv3intfield (lua_State *L, int index,
64
+ const char *fieldname, T &result)
65
+ {
66
+ lua_getfield (L, index , fieldname);
67
+ bool got = false ;
68
+ if (lua_istable (L, -1 )) {
69
+ got = getintfield (L, index , " x" , result.X ) ||
70
+ getintfield (L, index , " y" , result.Y ) ||
71
+ getintfield (L, index , " z" , result.Z );
72
+ }
73
+ lua_pop (L, 1 );
74
+ return got;
75
+ }
76
+
77
+ v3s16 getv3s16field_default (lua_State *L, int table,
78
+ const char *fieldname, v3s16 default_);
48
79
bool getstringfield (lua_State *L, int table,
49
80
const char *fieldname, std::string &result);
50
81
size_t getstringlistfield (lua_State *L, int table,
51
82
const char *fieldname,
52
83
std::vector<std::string> *result);
53
- bool getintfield (lua_State *L, int table,
54
- const char *fieldname, int &result);
55
- bool getintfield (lua_State *L, int table,
56
- const char *fieldname, u8 &result);
57
- bool getintfield (lua_State *L, int table,
58
- const char *fieldname, s8 &result);
59
- bool getintfield (lua_State *L, int table,
60
- const char *fieldname, u16 &result);
61
- bool getintfield (lua_State *L, int table,
62
- const char *fieldname, u32 &result);
63
84
void read_groups (lua_State *L, int index,
64
85
std::unordered_map<std::string, int > &result);
65
86
bool getboolfield (lua_State *L, int table,
66
87
const char *fieldname, bool &result);
67
88
bool getfloatfield (lua_State *L, int table,
68
89
const char *fieldname, float &result);
69
-
70
90
std::string checkstringfield (lua_State *L, int table,
71
91
const char *fieldname);
72
92
0 commit comments