aboutsummaryrefslogtreecommitdiff
path: root/src/compat.h
diff options
context:
space:
mode:
authorBenoit Germain <benoit.germain@ubisoft.com>2024-04-10 16:21:57 +0200
committerBenoit Germain <benoit.germain@ubisoft.com>2024-04-10 16:21:57 +0200
commit21e881fd6c085e615c438ceb6eb438712f5c5075 (patch)
treeca86d5360965f7dd2e81a978d3d8b821905b6710 /src/compat.h
parent408f8a5bf7934e7a5aa113fd3a55899db70dd73a (diff)
downloadlanes-21e881fd6c085e615c438ceb6eb438712f5c5075.tar.gz
lanes-21e881fd6c085e615c438ceb6eb438712f5c5075.tar.bz2
lanes-21e881fd6c085e615c438ceb6eb438712f5c5075.zip
C++ migration: wrap lua type values in an enum class for type safety and debugging purposes
Diffstat (limited to 'src/compat.h')
-rw-r--r--src/compat.h27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/compat.h b/src/compat.h
index 8ef1b6c..8d10e78 100644
--- a/src/compat.h
+++ b/src/compat.h
@@ -98,3 +98,30 @@ int lua_setiuservalue( lua_State* L, int idx, int n);
98#define LUA_ERRGCMM 666 // doesn't exist in Lua 5.4, we don't care about the actual value 98#define LUA_ERRGCMM 666 // doesn't exist in Lua 5.4, we don't care about the actual value
99 99
100#endif // LUA_VERSION_NUM == 504 100#endif // LUA_VERSION_NUM == 504
101
102// #################################################################################################
103
104// a wrapper over lua types to see them easier in a debugger
105enum class LuaType
106{
107 NONE = LUA_TNONE,
108 NIL = LUA_TNIL,
109 BOOLEAN = LUA_TBOOLEAN,
110 LIGHTUSERDATA = LUA_TLIGHTUSERDATA,
111 NUMBER = LUA_TNUMBER,
112 STRING = LUA_TSTRING,
113 TABLE = LUA_TTABLE,
114 FUNCTION = LUA_TFUNCTION,
115 USERDATA = LUA_TUSERDATA,
116 THREAD = LUA_TTHREAD,
117 CDATA = 10 // LuaJIT CDATA
118};
119
120inline LuaType lua_type_as_enum(lua_State* L, int idx_)
121{
122 return static_cast<LuaType>(lua_type(L, idx_));
123}
124inline char const* lua_typename(lua_State* L, LuaType t_)
125{
126 return lua_typename(L, static_cast<int>(t_));
127}