lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hello,

For a C-module [1] 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
       -- ...
end

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?

-- Jasper


[1] https://github.com/PG1003/filesystem