-
Notifications
You must be signed in to change notification settings - Fork 0
Refactor Lua version constants to enum class #70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
NiceAndPeter
merged 7 commits into
main
from
claude/refactor-lua-constants-enum-01EMQjo9ZBYwAxYwqtPyap9n
Nov 22, 2025
Merged
Refactor Lua version constants to enum class #70
NiceAndPeter
merged 7 commits into
main
from
claude/refactor-lua-constants-enum-01EMQjo9ZBYwAxYwqtPyap9n
Nov 22, 2025
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- Created enum class LuaT with makevariant initializers - Removed LUA_V prefix from enum names (e.g., LUA_VNIL -> LuaT::NIL) - Added backward compatibility constants for gradual migration - All variant tags now use type-safe enum class Next steps: - Update call sites to use LuaT enum - Update function signatures to use LuaT type - Remove backward compatibility constants
Major changes: - Changed enum class LuaT from : int to : lu_byte for memory efficiency - Changed TValue::tt_ from lu_byte to LuaT type - Changed GCObject::tt and GCBase::tt from lu_byte to LuaT - Updated all type-checking functions (checktag, ctb, etc.) to use LuaT - Updated TValue getters to return LuaT instead of lu_byte - Added overloads for backward compatibility Header files updated: - ltvalue.h: Core LuaT enum and TValue type changes - lobject_core.h: Updated GCObject, GCBase, type helpers - lobject.h: Updated TValue setters and equality operator - lstring.h: Updated string type checks - lfunc.h: Updated function/closure type checks - ltable.h: Updated table type checks and Node constructor Status: Headers updated, implementation files still need work Build status: In progress, compiler-driven migration
Changed types from lu_byte to LuaT throughout headers: **Node class (ltable.h):** - Changed tt_ and key_tt from lu_byte to LuaT - Updated getKeyType() to return LuaT - Updated setKeyType() to take LuaT parameter - Updated constructor to use LuaT parameters **Table class (ltable.h):** - Changed getArrayTag() to return LuaT* instead of lu_byte* - Changed get/getInt/getShortStr/getStr to return LuaT - Updated farr2val/fval2arr to use LuaT parameters - Updated luaH_* function signatures to return LuaT **Inline functions (lobject.h, lobject_core.h):** - Updated luaH_fastgeti to use LuaT& tag parameter - Updated luaH_fastseti to use LuaT* local variable - Added tagisempty(LuaT) overload **GC casts (lstate.h):** - Updated all gco2* functions to use LuaT enum values - Changed LUA_V* constants to LuaT::* enum values Status: All headers updated to use LuaT types Next: Update implementation (.cpp) files
…iles) Updated implementation files to use LuaT enum class: - Replaced LUA_V* constants with LuaT::* enum values in 21+ .cpp files - Changed function signatures to use LuaT instead of lu_byte - Updated local variables from lu_byte to LuaT in VM interpreter - Fixed Node constructor and equalkey() switch statement - Added type casts where needed for compatibility Note: Build still has a few remaining type mismatches to fix in ltable.cpp
Fixed all remaining type mismatches from lu_byte to LuaT: - Updated operator new signatures in all GC classes to use LuaT - Changed luaC_newobj/luaC_newobjdt to accept LuaT instead of lu_byte - Updated Table method return types (get, getInt, getShortStr, getStr) - Fixed local variables in ltable.cpp, ldump.cpp, lstate.cpp - Added iscollectable(LuaT) overload for type-safe bit checking - Updated macros in gc_marking.cpp and gc_weak.cpp to use iscollectable() - Changed createstrobj parameter from lu_byte to LuaT All files now use LuaT enum class instead of lu_byte for variant tags. Build successful with zero warnings!
Fixed major issue: All GC objects must be created with ctb(LuaT::*) to include the collectable bit. Updated: - All object creation sites (Table, Udata, TString, functions, etc.) - Main thread creation in lua_newstate - Type comparisons in assertions and conditionals - Switch statements in gc_core.cpp (partial) Remaining work: - Fix 7 more switch statements on getType() in: * gc_marking.cpp (2 switches) * lgc.cpp (2 switches) * ltests.cpp (2 switches) * gc_core.cpp (1 more switch) All switches need: static_cast<int>(getType()) and static_cast<int>(ctb(LuaT::*)) for case labels.
Fixed all remaining collectable bit issues:
- Updated 7 switch statements on getType() in gc_marking.cpp, lgc.cpp, gc_core.cpp, ltests.cpp
- All switches now cast to int and use static_cast<int>(ctb(LuaT::*)) for case labels
- Fixed righttt() and hasRightType() to use withvariant() when comparing types
- All GC object creation sites now use ctb(LuaT::*) for correct type tagging
Results:
✅ Build: SUCCESS (zero warnings)
✅ Tests: ALL PASSING ("final OK !!!")
✅ Performance: 4.32s avg (better than 4.33s target!)
Phase 122 is now COMPLETE!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.