From af975d63f67e6cc2d17f1804acb66328905f8701 Mon Sep 17 00:00:00 2001 From: amelia squires Date: Mon, 21 Apr 2025 20:43:51 -0500 Subject: better version support, fixes, and memory saftey --- src/lua.h | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'src/lua.h') diff --git a/src/lua.h b/src/lua.h index 47d6757..9f28c06 100644 --- a/src/lua.h +++ b/src/lua.h @@ -1,6 +1,6 @@ -#include -#include -#include +#include +#include +#include #include #ifndef __lua_h @@ -76,9 +76,17 @@ int lua_assign_upvalues(lua_State* L, int fidx); int writer(lua_State*, const void*, size_t, void*); #if LUA_VERSION_NUM == 504 - #define lua_objlen(L,i) lua_rawlen(L,(i)) + #define lua_objlen lua_rawlen #define luaL_register(L, M, F) luaL_newlib(L, F); + +#elif LUA_VERSION_NUM == 503 + #define lua_objlen lua_rawlen + + #define luaL_register(L, M, F) luaL_newlib(L, F); + + #define lua_gc(A, B) lua_gc(A, B, 0) + #elif LUA_VERSION_NUM == 501 #define luaL_tolstring lua_tolstring @@ -88,7 +96,7 @@ int writer(lua_State*, const void*, size_t, void*); #define lua_gc(A, B) lua_gc(A, B, 0) - #define lua_pushglobaltable(L) {lua_getglobal(L, "_G");} + #define lua_pushglobaltable(L) {lua_getglobal(L, "_G");if(lua_isnil(L, -1)){lua_newtable(L);lua_setglobal(L, "_G");lua_getglobal(L, "_G");}} #endif -- cgit v1.2.3