diff options
author | kwolekr <kwolekr@minetest.net> | 2015-04-19 21:42:40 -0400 |
---|---|---|
committer | kwolekr <kwolekr@minetest.net> | 2015-04-19 21:42:40 -0400 |
commit | 3d4244cc75b7e75565476032851fbd30d5cd9306 (patch) | |
tree | 9d1e7ad8b44d93d62a559f62bcc97639f6759037 /src/script/common | |
parent | 687d969c9c50be98597ee9f383280517f1f8cd97 (diff) | |
download | minetest-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')
-rw-r--r-- | src/script/common/c_content.cpp | 18 | ||||
-rw-r--r-- | src/script/common/c_converter.cpp | 52 | ||||
-rw-r--r-- | src/script/common/c_converter.h | 6 |
3 files changed, 68 insertions, 8 deletions
diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp index 8bb22186b..8f82b692a 100644 --- a/src/script/common/c_content.cpp +++ b/src/script/common/c_content.cpp @@ -983,14 +983,16 @@ bool read_noiseparams(lua_State *L, int index, NoiseParams *np) if (!lua_istable(L, index)) return false; - np->offset = getfloatfield_default(L, index, "offset", 0.0); - np->scale = getfloatfield_default(L, index, "scale", 0.0); - np->persist = getfloatfield_default(L, index, "persist", 0.0); - np->lacunarity = getfloatfield_default(L, index, "lacunarity", 2.0); - np->seed = getintfield_default(L, index, "seed", 0); - np->octaves = getintfield_default(L, index, "octaves", 0); - - u32 flags = 0, flagmask = 0; + getfloatfield(L, index, "offset", np->offset); + getfloatfield(L, index, "scale", np->scale); + getfloatfield(L, index, "persist", np->persist); + getfloatfield(L, index, "persistence", np->persist); + getfloatfield(L, index, "lacunarity", np->lacunarity); + getintfield(L, index, "seed", np->seed); + getintfield(L, index, "octaves", np->octaves); + + u32 flags = 0; + u32 flagmask = 0; np->flags = getflagsfield(L, index, "flags", flagdesc_noiseparams, &flags, &flagmask) ? flags : NOISE_FLAG_DEFAULTS; 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) { diff --git a/src/script/common/c_converter.h b/src/script/common/c_converter.h index fdcd0c8fc..1d5be6971 100644 --- a/src/script/common/c_converter.h +++ b/src/script/common/c_converter.h @@ -53,6 +53,10 @@ size_t getstringlistfield(lua_State *L, int table, std::vector<std::string> *result); bool getintfield(lua_State *L, int table, const char *fieldname, int &result); +bool getintfield(lua_State *L, int table, + const char *fieldname, u16 &result); +bool getintfield(lua_State *L, int table, + const char *fieldname, u32 &result); void read_groups(lua_State *L, int index, std::map<std::string, int> &result); bool getboolfield(lua_State *L, int table, @@ -72,6 +76,8 @@ void setboolfield(lua_State *L, int table, v3f checkFloatPos (lua_State *L, int index); +v2f check_v2f (lua_State *L, int index); +v2s16 check_v2s16 (lua_State *L, int index); v3f check_v3f (lua_State *L, int index); v3s16 check_v3s16 (lua_State *L, int index); |