1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Add 'persistence' alias for Lua noiseparams and validate more vector parameters

This commit is contained in:
kwolekr 2015-04-19 21:42:40 -04:00
parent 687d969c9c
commit 3d4244cc75
4 changed files with 73 additions and 13 deletions

View file

@ -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)
{