[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Exposing emum flags from the C-API
- From: "Jasper Klein" <jasper@...>
- Date: Thu, 14 Jul 2022 22:19:46 +0200
For a C-module  I've wrapped enums in an userdata with a metatable that implements the binary operators.
This works fine but has two downsides.
For example when checking if a permission is set;
if variable_with_permissions & ~perms.owner_write == perms.owner_write then
1) The '== perms.owner_write' part is required because an if-statement evaluates uservalues as true.
'__eq' metamethod is only called when both operands are a table or userdata.
2) The '&' and '~' operators create a new uservalues that are immediately garbage.
Are these downsides really an issue?
How would you expose enum members (not the values) from the C-API to Lua that are used as flags which can be combined?