aboutsummaryrefslogtreecommitdiff
path: root/src/bitflags.c
diff options
context:
space:
mode:
authorThijs Schreijer <thijs@thijsschreijer.nl>2024-05-23 08:23:14 +0200
committerThijs Schreijer <thijs@thijsschreijer.nl>2024-05-23 08:23:14 +0200
commit7e9447c98588730738724176d9acc595be6299e6 (patch)
tree7bec18966d7e4f4078a0be5cb6cf4f8db3dc5ece /src/bitflags.c
parentb3cd71ddf2bbadb63fa4dc4ef1147b5c4ae95994 (diff)
downloadluasystem-7e9447c98588730738724176d9acc595be6299e6.tar.gz
luasystem-7e9447c98588730738724176d9acc595be6299e6.tar.bz2
luasystem-7e9447c98588730738724176d9acc595be6299e6.zip
fix several tests
Diffstat (limited to 'src/bitflags.c')
-rw-r--r--src/bitflags.c26
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.
54LSBF_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/***
50Creates a new bitflag object from the given value. 76Creates a new bitflag object from the given value.
51@function system.bitflag 77@function system.bitflag