summaryrefslogtreecommitdiff
path: root/src/script/common/c_converter.cpp
diff options
context:
space:
mode:
authorkwolekr <kwolekr@minetest.net>2015-04-19 21:42:40 -0400
committerkwolekr <kwolekr@minetest.net>2015-04-19 21:42:40 -0400
commit3d4244cc75b7e75565476032851fbd30d5cd9306 (patch)
tree9d1e7ad8b44d93d62a559f62bcc97639f6759037 /src/script/common/c_converter.cpp
parent687d969c9c50be98597ee9f383280517f1f8cd97 (diff)
downloadminetest-3d4244cc75b7e75565476032851fbd30d5cd9306.tar.gz
minetest-3d4244cc75b7e75565476032851fbd30d5cd9306.tar.bz2
minetest-3d4244cc75b7e75565476032851fbd30d5cd9306.zip
Add 'persistence' alias for Lua noiseparams and validate more vector parameters
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)
{