diff options
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); |