diff options
author | Thijs Schreijer <thijs@thijsschreijer.nl> | 2024-05-23 08:23:14 +0200 |
---|---|---|
committer | Thijs Schreijer <thijs@thijsschreijer.nl> | 2024-05-23 08:23:14 +0200 |
commit | 7e9447c98588730738724176d9acc595be6299e6 (patch) | |
tree | 7bec18966d7e4f4078a0be5cb6cf4f8db3dc5ece /src/bitflags.c | |
parent | b3cd71ddf2bbadb63fa4dc4ef1147b5c4ae95994 (diff) | |
download | luasystem-7e9447c98588730738724176d9acc595be6299e6.tar.gz luasystem-7e9447c98588730738724176d9acc595be6299e6.tar.bz2 luasystem-7e9447c98588730738724176d9acc595be6299e6.zip |
fix several tests
Diffstat (limited to 'src/bitflags.c')
-rw-r--r-- | src/bitflags.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/bitflags.c b/src/bitflags.c index 39f8af0..e397918 100644 --- a/src/bitflags.c +++ b/src/bitflags.c | |||
@@ -46,6 +46,32 @@ LSBF_BITFLAG lsbf_checkbitflags(lua_State *L, int index) { | |||
46 | return obj->flags; | 46 | return obj->flags; |
47 | } | 47 | } |
48 | 48 | ||
49 | // Validates that the given index is a table containing a field 'fieldname' | ||
50 | // which is a bitflag object and returns its value. | ||
51 | // If the index is not a table or the field is not a bitflag object, a Lua | ||
52 | // error is raised. If the bitflag is not present, the default value is returned. | ||
53 | // The stack remains unchanged. | ||
54 | LSBF_BITFLAG lsbf_checkbitflagsfield(lua_State *L, int index, const char *fieldname, LSBF_BITFLAG default_value) { | ||
55 | luaL_checktype(L, index, LUA_TTABLE); | ||
56 | lua_getfield(L, index, fieldname); | ||
57 | |||
58 | // if null, return default value | ||
59 | if (lua_isnil(L, -1)) { | ||
60 | lua_pop(L, 1); | ||
61 | return default_value; | ||
62 | } | ||
63 | |||
64 | // check to bitflags | ||
65 | LS_BitFlags *obj = luaL_testudata(L, -1, BITFLAGS_MT_NAME); | ||
66 | if (obj == NULL) { | ||
67 | lua_pop(L, 1); | ||
68 | return luaL_error(L, "bad argument #%d, field '%s' must be a bitflag object", index, fieldname); | ||
69 | } | ||
70 | LSBF_BITFLAG value = obj->flags; | ||
71 | lua_pop(L, 1); | ||
72 | return value; | ||
73 | } | ||
74 | |||
49 | /*** | 75 | /*** |
50 | Creates a new bitflag object from the given value. | 76 | Creates a new bitflag object from the given value. |
51 | @function system.bitflag | 77 | @function system.bitflag |