summaryrefslogtreecommitdiff
path: root/src/script/common/c_converter.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/script/common/c_converter.cpp')
-rw-r--r--src/script/common/c_converter.cpp52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/script/common/c_converter.cpp b/src/script/common/c_converter.cpp
index 5070dca2d..755485ee4 100644
--- a/src/script/common/c_converter.cpp
+++ b/src/script/common/c_converter.cpp
@@ -59,6 +59,19 @@ v2s16 read_v2s16(lua_State *L, int index)
return p;
}
+v2s16 check_v2s16(lua_State *L, int index)
+{
+ v2s16 p;
+ luaL_checktype(L, index, LUA_TTABLE);
+ lua_getfield(L, index, "x");
+ p.X = luaL_checknumber(L, -1);
+ lua_pop(L, 1);
+ lua_getfield(L, index, "y");
+ p.Y = luaL_checknumber(L, -1);
+ lua_pop(L, 1);
+ return p;
+}
+
v2s32 read_v2s32(lua_State *L, int index)
{
v2s32 p;
@@ -85,6 +98,19 @@ v2f read_v2f(lua_State *L, int index)
return p;
}
+v2f check_v2f(lua_State *L, int index)
+{
+ v2f p;
+ luaL_checktype(L, index, LUA_TTABLE);
+ lua_getfield(L, index, "x");
+ p.X = luaL_checknumber(L, -1);
+ lua_pop(L, 1);
+ lua_getfield(L, index, "y");
+ p.Y = luaL_checknumber(L, -1);
+ lua_pop(L, 1);
+ return p;
+}
+
v3f read_v3f(lua_State *L, int index)
{
v3f pos;
@@ -285,6 +311,32 @@ bool getintfield(lua_State *L, int table,
return got;
}
+bool getintfield(lua_State *L, int table,
+ const char *fieldname, u16 &result)
+{
+ lua_getfield(L, table, fieldname);
+ bool got = false;
+ if(lua_isnumber(L, -1)){
+ result = lua_tonumber(L, -1);
+ got = true;
+ }
+ lua_pop(L, 1);
+ return got;
+}
+
+bool getintfield(lua_State *L, int table,
+ const char *fieldname, u32 &result)
+{
+ lua_getfield(L, table, fieldname);
+ bool got = false;
+ if(lua_isnumber(L, -1)){
+ result = lua_tonumber(L, -1);
+ got = true;
+ }
+ lua_pop(L, 1);
+ return got;
+}
+
bool getfloatfield(lua_State *L, int table,
const char *fieldname, float &result)
{