Skip to content

Commit e03b75f

Browse files
committed
Phase 122: Add enum class LuaT for variant tags (part 1)
- 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
1 parent eaceeaa commit e03b75f

File tree

1 file changed

+52
-29
lines changed

1 file changed

+52
-29
lines changed

src/objects/ltvalue.h

Lines changed: 52 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -35,44 +35,67 @@ inline constexpr int LUA_TPROTO = (LUA_NUMTYPES+1); /* function prototypes */
3535
** ===================================================================
3636
*/
3737

38-
/* Nil variants */
39-
inline constexpr int LUA_VNIL = makevariant(LUA_TNIL, 0);
40-
inline constexpr int LUA_VEMPTY = makevariant(LUA_TNIL, 1);
41-
inline constexpr int LUA_VABSTKEY = makevariant(LUA_TNIL, 2);
42-
inline constexpr int LUA_VNOTABLE = makevariant(LUA_TNIL, 3);
38+
enum class LuaT : int {
39+
/* Nil variants */
40+
NIL = makevariant(LUA_TNIL, 0),
41+
EMPTY = makevariant(LUA_TNIL, 1),
42+
ABSTKEY = makevariant(LUA_TNIL, 2),
43+
NOTABLE = makevariant(LUA_TNIL, 3),
4344

44-
/* Boolean variants */
45-
inline constexpr int LUA_VFALSE = makevariant(LUA_TBOOLEAN, 0);
46-
inline constexpr int LUA_VTRUE = makevariant(LUA_TBOOLEAN, 1);
45+
/* Boolean variants */
46+
VFALSE = makevariant(LUA_TBOOLEAN, 0),
47+
VTRUE = makevariant(LUA_TBOOLEAN, 1),
4748

48-
/* Number variants */
49-
inline constexpr int LUA_VNUMINT = makevariant(LUA_TNUMBER, 0); /* integer numbers */
50-
inline constexpr int LUA_VNUMFLT = makevariant(LUA_TNUMBER, 1); /* float numbers */
49+
/* Number variants */
50+
NUMINT = makevariant(LUA_TNUMBER, 0), /* integer numbers */
51+
NUMFLT = makevariant(LUA_TNUMBER, 1), /* float numbers */
5152

52-
/* String variants */
53-
inline constexpr int LUA_VSHRSTR = makevariant(LUA_TSTRING, 0); /* short strings */
54-
inline constexpr int LUA_VLNGSTR = makevariant(LUA_TSTRING, 1); /* long strings */
53+
/* String variants */
54+
SHRSTR = makevariant(LUA_TSTRING, 0), /* short strings */
55+
LNGSTR = makevariant(LUA_TSTRING, 1), /* long strings */
5556

56-
/* Table variant */
57-
inline constexpr int LUA_VTABLE = makevariant(LUA_TTABLE, 0);
57+
/* Table variant */
58+
TABLE = makevariant(LUA_TTABLE, 0),
5859

59-
/* Function variants */
60-
inline constexpr int LUA_VLCL = makevariant(LUA_TFUNCTION, 0); /* Lua closure */
61-
inline constexpr int LUA_VLCF = makevariant(LUA_TFUNCTION, 1); /* light C function */
62-
inline constexpr int LUA_VCCL = makevariant(LUA_TFUNCTION, 2); /* C closure */
60+
/* Function variants */
61+
LCL = makevariant(LUA_TFUNCTION, 0), /* Lua closure */
62+
LCF = makevariant(LUA_TFUNCTION, 1), /* light C function */
63+
CCL = makevariant(LUA_TFUNCTION, 2), /* C closure */
6364

64-
/* Userdata variants */
65-
inline constexpr int LUA_VLIGHTUSERDATA = makevariant(LUA_TLIGHTUSERDATA, 0);
66-
inline constexpr int LUA_VUSERDATA = makevariant(LUA_TUSERDATA, 0);
65+
/* Userdata variants */
66+
LIGHTUSERDATA = makevariant(LUA_TLIGHTUSERDATA, 0),
67+
USERDATA = makevariant(LUA_TUSERDATA, 0),
6768

68-
/* Thread variant */
69-
inline constexpr int LUA_VTHREAD = makevariant(LUA_TTHREAD, 0);
69+
/* Thread variant */
70+
THREAD = makevariant(LUA_TTHREAD, 0),
7071

71-
/* Upvalue variant (collectable non-value) */
72-
inline constexpr int LUA_VUPVAL = makevariant(LUA_TUPVAL, 0);
72+
/* Upvalue variant (collectable non-value) */
73+
UPVAL = makevariant(LUA_TUPVAL, 0),
7374

74-
/* Proto variant (collectable non-value) */
75-
inline constexpr int LUA_VPROTO = makevariant(LUA_TPROTO, 0);
75+
/* Proto variant (collectable non-value) */
76+
PROTO = makevariant(LUA_TPROTO, 0)
77+
};
78+
79+
/* Backward compatibility constants (to be removed after migration) */
80+
inline constexpr int LUA_VNIL = static_cast<int>(LuaT::NIL);
81+
inline constexpr int LUA_VEMPTY = static_cast<int>(LuaT::EMPTY);
82+
inline constexpr int LUA_VABSTKEY = static_cast<int>(LuaT::ABSTKEY);
83+
inline constexpr int LUA_VNOTABLE = static_cast<int>(LuaT::NOTABLE);
84+
inline constexpr int LUA_VFALSE = static_cast<int>(LuaT::VFALSE);
85+
inline constexpr int LUA_VTRUE = static_cast<int>(LuaT::VTRUE);
86+
inline constexpr int LUA_VNUMINT = static_cast<int>(LuaT::NUMINT);
87+
inline constexpr int LUA_VNUMFLT = static_cast<int>(LuaT::NUMFLT);
88+
inline constexpr int LUA_VSHRSTR = static_cast<int>(LuaT::SHRSTR);
89+
inline constexpr int LUA_VLNGSTR = static_cast<int>(LuaT::LNGSTR);
90+
inline constexpr int LUA_VTABLE = static_cast<int>(LuaT::TABLE);
91+
inline constexpr int LUA_VLCL = static_cast<int>(LuaT::LCL);
92+
inline constexpr int LUA_VLCF = static_cast<int>(LuaT::LCF);
93+
inline constexpr int LUA_VCCL = static_cast<int>(LuaT::CCL);
94+
inline constexpr int LUA_VLIGHTUSERDATA = static_cast<int>(LuaT::LIGHTUSERDATA);
95+
inline constexpr int LUA_VUSERDATA = static_cast<int>(LuaT::USERDATA);
96+
inline constexpr int LUA_VTHREAD = static_cast<int>(LuaT::THREAD);
97+
inline constexpr int LUA_VUPVAL = static_cast<int>(LuaT::UPVAL);
98+
inline constexpr int LUA_VPROTO = static_cast<int>(LuaT::PROTO);
7699

77100
/* }================================================================== */
78101

0 commit comments

Comments
 (0)