CyberEngineTweaks icon indicating copy to clipboard operation
CyberEngineTweaks copied to clipboard

Fix integer sizing in Enum

Open googleben opened this issue 7 months ago • 5 comments

Fixes https://github.com/maximegmd/CyberEngineTweaks/issues/888.

Pretty straightforward changes - mainly just converted Enum.m_value to a union and wrote conversions where needed. Important bits:

  • Two constructors still only take int32_t which theoretically isn't wide enough, but they're currently only called using numbers from Lua which aren't precise enough either. Could be fixed, but a cursory scan didn't turn up anything currently in the game that's large enough to need more than an int32, so I didn't worry about it
  • I went ahead and switched to all signed numbers. I haven't seen anything that seems unsigned, but there's quite a lot of obviously negative numbers, so this seems reasonable to me
  • I modified the EnumInt function exposed to Lua to return a correctly sized int. This isn't strictly necessary and it could just be an Int64 if that's preferred
  • For testing I created enums for every size that each had values of 0, 1, 2, -1, -2, and the max and min values for the type. Everything seemed to work correctly, except of course that Lua can't represent max int64_t with its native numbers
  • I made sure all the Enum constructors work correctly from Lua

Let me know if there's any changes I need to make or other information you need!

googleben avatar Nov 09 '23 10:11 googleben