diff options
author | kwolekr <kwolekr@minetest.net> | 2014-03-08 11:34:46 -0500 |
---|---|---|
committer | kwolekr <kwolekr@minetest.net> | 2014-03-08 11:35:04 -0500 |
commit | 28d6326bd42a88d5a9245c70d7044d19e4d07954 (patch) | |
tree | cfd4e8d83fa241a7ec76e2f1975e7a61b8de108e /src/script/common | |
parent | db98ef6b4553e7b7cb99589740dc219902a90fbc (diff) | |
download | minetest-28d6326bd42a88d5a9245c70d7044d19e4d07954.tar.gz minetest-28d6326bd42a88d5a9245c70d7044d19e4d07954.tar.bz2 minetest-28d6326bd42a88d5a9245c70d7044d19e4d07954.zip |
Update set_mapgen_params and set_gen_notify Lua API to use new flag format
Diffstat (limited to 'src/script/common')
-rw-r--r-- | src/script/common/c_content.cpp | 31 | ||||
-rw-r--r-- | src/script/common/c_content.h | 9 |
2 files changed, 27 insertions, 13 deletions
diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp index 74e1b0956..899e1c536 100644 --- a/src/script/common/c_content.cpp +++ b/src/script/common/c_content.cpp @@ -840,23 +840,32 @@ void push_hit_params(lua_State *L,const HitParams ¶ms) } /******************************************************************************/ -u32 getflagsfield(lua_State *L, int table, const char *fieldname, - FlagDesc *flagdesc, u32 *flagmask) + +bool getflagsfield(lua_State *L, int table, const char *fieldname, + FlagDesc *flagdesc, u32 *flags, u32 *flagmask) { - u32 flags = 0; - lua_getfield(L, table, fieldname); - if (lua_isstring(L, -1)) { - std::string flagstr = lua_tostring(L, -1); - flags = readFlagString(flagstr, flagdesc, flagmask); - } else if (lua_istable(L, -1)) { - flags = read_flags_table(L, -1, flagdesc, flagmask); - } + bool success = read_flags(L, -1, flagdesc, flags, flagmask); lua_pop(L, 1); - return flags; + return success; +} + +bool read_flags(lua_State *L, int index, FlagDesc *flagdesc, + u32 *flags, u32 *flagmask) +{ + if (lua_isstring(L, index)) { + std::string flagstr = lua_tostring(L, index); + *flags = readFlagString(flagstr, flagdesc, flagmask); + } else if (lua_istable(L, index)) { + *flags = read_flags_table(L, index, flagdesc, flagmask); + } else { + return false; + } + + return true; } u32 read_flags_table(lua_State *L, int table, FlagDesc *flagdesc, u32 *flagmask) diff --git a/src/script/common/c_content.h b/src/script/common/c_content.h index 9aed5ccfa..f48c673bd 100644 --- a/src/script/common/c_content.h +++ b/src/script/common/c_content.h @@ -119,9 +119,14 @@ int getenumfield (lua_State *L, const EnumString *spec, int default_); -u32 getflagsfield (lua_State *L, int table, +bool getflagsfield (lua_State *L, int table, const char *fieldname, - FlagDesc *flagdesc, u32 *flagmask); + FlagDesc *flagdesc, + u32 *flags, u32 *flagmask); + +bool read_flags (lua_State *L, int index, + FlagDesc *flagdesc, + u32 *flags, u32 *flagmask); u32 read_flags_table (lua_State *L, int table, FlagDesc *flagdesc, u32 *flagmask); |