aboutsummaryrefslogtreecommitdiff
path: root/src/compat.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/compat.h')
-rw-r--r--src/compat.h72
1 files changed, 33 insertions, 39 deletions
diff --git a/src/compat.h b/src/compat.h
index b5afe17..f097fb6 100644
--- a/src/compat.h
+++ b/src/compat.h
@@ -31,6 +31,33 @@ extern "C"
31 31
32// ################################################################################################# 32// #################################################################################################
33 33
34// a strong-typed wrapper over lua types to see them easier in a debugger
35enum class LuaType
36{
37 NONE = LUA_TNONE,
38 NIL = LUA_TNIL,
39 BOOLEAN = LUA_TBOOLEAN,
40 LIGHTUSERDATA = LUA_TLIGHTUSERDATA,
41 NUMBER = LUA_TNUMBER,
42 STRING = LUA_TSTRING,
43 TABLE = LUA_TTABLE,
44 FUNCTION = LUA_TFUNCTION,
45 USERDATA = LUA_TUSERDATA,
46 THREAD = LUA_TTHREAD,
47 CDATA = 10 // LuaJIT CDATA
48};
49
50inline LuaType lua_type_as_enum(lua_State* L_, int idx_)
51{
52 return static_cast<LuaType>(lua_type(L_, idx_));
53}
54inline char const* lua_typename(lua_State* L_, LuaType t_)
55{
56 return lua_typename(L_, static_cast<int>(t_));
57}
58
59// #################################################################################################
60
34// add some Lua 5.3-style API when building for Lua 5.1 61// add some Lua 5.3-style API when building for Lua 5.1
35#if LUA_VERSION_NUM == 501 62#if LUA_VERSION_NUM == 501
36 63
@@ -106,22 +133,16 @@ inline int lua504_dump(lua_State* L_, lua_Writer writer_, void* data_, [[maybe_u
106 133
107// ################################################################################################# 134// #################################################################################################
108 135
109#if LUA_VERSION_NUM < 503 136[[nodiscard]] inline LuaType luaG_getfield(lua_State* L_, int idx_, char const* k_)
110// starting with Lua 5.3, lua_getfield returns the type of the value it found
111inline int lua503_getfield(lua_State* L_, int idx_, char const* k_)
112{ 137{
138// starting with Lua 5.3, lua_getfield returns the type of the value it found
139#if LUA_VERSION_NUM < 503
113 lua_getfield(L_, idx_, k_); 140 lua_getfield(L_, idx_, k_);
114 return lua_type(L_, -1); 141 return lua_type_as_enum(L_, -1);
115}
116
117#else // LUA_VERSION_NUM >= 503 142#else // LUA_VERSION_NUM >= 503
118 143 return static_cast<LuaType>(lua_getfield(L_, idx_, k_));
119inline int lua503_getfield(lua_State* L_, int idx_, char const* k_)
120{
121 return lua_getfield(L_, idx_, k_);
122}
123
124#endif // LUA_VERSION_NUM >= 503 144#endif // LUA_VERSION_NUM >= 503
145}
125 146
126// ################################################################################################# 147// #################################################################################################
127 148
@@ -202,33 +223,6 @@ inline int luaL_optint(lua_State* L_, int n_, lua_Integer d_)
202 223
203// ################################################################################################# 224// #################################################################################################
204 225
205// a strong-typed wrapper over lua types to see them easier in a debugger
206enum class LuaType
207{
208 NONE = LUA_TNONE,
209 NIL = LUA_TNIL,
210 BOOLEAN = LUA_TBOOLEAN,
211 LIGHTUSERDATA = LUA_TLIGHTUSERDATA,
212 NUMBER = LUA_TNUMBER,
213 STRING = LUA_TSTRING,
214 TABLE = LUA_TTABLE,
215 FUNCTION = LUA_TFUNCTION,
216 USERDATA = LUA_TUSERDATA,
217 THREAD = LUA_TTHREAD,
218 CDATA = 10 // LuaJIT CDATA
219};
220
221inline LuaType lua_type_as_enum(lua_State* L_, int idx_)
222{
223 return static_cast<LuaType>(lua_type(L_, idx_));
224}
225inline char const* lua_typename(lua_State* L_, LuaType t_)
226{
227 return lua_typename(L_, static_cast<int>(t_));
228}
229
230// #################################################################################################
231
232// a strong-typed wrapper over lua error codes to see them easier in a debugger 226// a strong-typed wrapper over lua error codes to see them easier in a debugger
233enum class LuaError 227enum class LuaError
234{ 228{