Expose a `constants` dictionary to Lua.
C people:
-
lib_getenum
works functionally identically to how it worked before I made any changes. - The difference is now
getEnum
contains the main comparison portion. - The
constants
userdata uses an anonymous metatable.
Lua people:
- A new userdata named
constants
now exists for you to get the value of a constant, or check if it exists. This is helpful for seeing if a value in_G
is a constant or not. - This read-only userdata expects table accesses with strings as keys. Failed accesses will return
nil
with no errors.
Example:print(constants["FRACUNIT"]) -- 65536
-
userdata
andfunction
type variables are excluded fromconstants
, soA_*
andsuper
aren't considered constants.
Attached is a Lua script you can use to test the code.
constantTable.lua
Edited by Golden