From 3570f3e396acad4a6b5381d06c2dae5cf4e95fbd Mon Sep 17 00:00:00 2001 From: kwolekr Date: Sat, 15 Feb 2014 18:20:15 -0500 Subject: Add minetest.set_noiseparam_defaults() Lua API --- src/script/common/c_content.cpp | 27 +++++++++++++++++++-------- src/script/common/c_content.h | 3 +++ 2 files changed, 22 insertions(+), 8 deletions(-) (limited to 'src/script/common') diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp index 8e4da1b05..74e1b0956 100644 --- a/src/script/common/c_content.cpp +++ b/src/script/common/c_content.cpp @@ -958,25 +958,36 @@ void luaentity_get(lua_State *L, u16 id) /******************************************************************************/ NoiseParams *read_noiseparams(lua_State *L, int index) +{ + NoiseParams *np = new NoiseParams; + + if (!read_noiseparams_nc(L, index, np)) { + delete np; + np = NULL; + } + + return np; +} + +bool read_noiseparams_nc(lua_State *L, int index, NoiseParams *np) { if (index < 0) index = lua_gettop(L) + 1 + index; if (!lua_istable(L, index)) - return NULL; + return false; - NoiseParams *np = new NoiseParams; + 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->seed = getintfield_default(L, index, "seed", 0); + np->octaves = getintfield_default(L, index, "octaves", 0); - np->offset = getfloatfield_default(L, index, "offset", 0.0); - np->scale = getfloatfield_default(L, index, "scale", 0.0); lua_getfield(L, index, "spread"); np->spread = read_v3f(L, -1); lua_pop(L, 1); - np->seed = getintfield_default(L, index, "seed", 0); - np->octaves = getintfield_default(L, index, "octaves", 0); - np->persist = getfloatfield_default(L, index, "persist", 0.0); - return np; + return true; } /******************************************************************************/ diff --git a/src/script/common/c_content.h b/src/script/common/c_content.h index 61617d7ab..9aed5ccfa 100644 --- a/src/script/common/c_content.h +++ b/src/script/common/c_content.h @@ -144,6 +144,9 @@ bool string_to_enum (const EnumString *spec, NoiseParams* read_noiseparams (lua_State *L, int index); +bool read_noiseparams_nc (lua_State *L, int index, + NoiseParams *np); + bool read_schematic (lua_State *L, int index, DecoSchematic *dschem, Server *server); -- cgit v1.2.3