aboutsummaryrefslogtreecommitdiff
path: root/src/compat.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/compat.h')
-rw-r--r--src/compat.h28
1 files changed, 27 insertions, 1 deletions
diff --git a/src/compat.h b/src/compat.h
index bf22f10..0e95cde 100644
--- a/src/compat.h
+++ b/src/compat.h
@@ -24,6 +24,8 @@ extern "C"
24#define LUA_JITLIBNAME "jit" 24#define LUA_JITLIBNAME "jit"
25#endif // LUA_JITLIBNAME 25#endif // LUA_JITLIBNAME
26 26
27#include <cassert>
28
27// code is now preferring Lua 5.4 API 29// code is now preferring Lua 5.4 API
28 30
29// ################################################################################################# 31// #################################################################################################
@@ -160,6 +162,8 @@ void* lua_newuserdatauv(lua_State* L_, size_t sz_, int nuvalue_);
160int lua_getiuservalue(lua_State* L_, int idx_, int n_); 162int lua_getiuservalue(lua_State* L_, int idx_, int n_);
161int lua_setiuservalue(lua_State* L_, int idx_, int n_); 163int lua_setiuservalue(lua_State* L_, int idx_, int n_);
162 164
165#define LUA_GNAME "_G"
166
163#endif // LUA_VERSION_NUM < 504 167#endif // LUA_VERSION_NUM < 504
164 168
165// ################################################################################################# 169// #################################################################################################
@@ -197,7 +201,7 @@ inline int luaL_optint(lua_State* L_, int n_, lua_Integer d_)
197 201
198// ################################################################################################# 202// #################################################################################################
199 203
200// a wrapper over lua types to see them easier in a debugger 204// a strong-typed wrapper over lua types to see them easier in a debugger
201enum class LuaType 205enum class LuaType
202{ 206{
203 NONE = LUA_TNONE, 207 NONE = LUA_TNONE,
@@ -222,4 +226,26 @@ inline char const* lua_typename(lua_State* L_, LuaType t_)
222 return lua_typename(L_, static_cast<int>(t_)); 226 return lua_typename(L_, static_cast<int>(t_));
223} 227}
224 228
229// #################################################################################################
230
231// a strong-typed wrapper over lua error codes to see them easier in a debugger
232enum class LuaError
233{
234 OK = LUA_OK,
235 YIELD = LUA_YIELD,
236 ERRRUN = LUA_ERRRUN,
237 ERRSYNTAX = LUA_ERRSYNTAX,
238 ERRMEM = LUA_ERRMEM,
239 ERRGCMM = LUA_ERRGCMM, // pre-5.4
240 ERRERR = LUA_ERRERR
241};
242
243inline constexpr LuaError ToLuaError(int rc_)
244{
245 assert(rc_ == LUA_OK || rc_ == LUA_YIELD || rc_ == LUA_ERRRUN || rc_ == LUA_ERRSYNTAX || rc_ == LUA_ERRMEM || rc_ == LUA_ERRGCMM || rc_ == LUA_ERRERR);
246 return static_cast<LuaError>(rc_);
247}
248
249// #################################################################################################
250
225LuaType luaG_getmodule(lua_State* L_, char const* name_); 251LuaType luaG_getmodule(lua_State* L_, char const* name_);