Skip to content

Expose a `constants` dictionary to Lua.

Golden requested to merge Golden/SRB2:constants-global into next

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 and function type variables are excluded from constants, so A_* and super aren't considered constants.

Attached is a Lua script you can use to test the code.
constantTable.lua

Edited by Golden

Merge request reports