77#ifndef ELUNACOMPAT_H
88#define ELUNACOMPAT_H
99
10+ #if defined ELUNA_LUAU
11+ // Luau uses C++ linkage and exceptions. Do not wrap these headers in extern C.
12+ #include "lua.h"
13+ #include "lualib.h"
14+ #else
1015extern "C"
1116{
1217#include "lua.h"
18+ #include "lualib.h"
1319#include "lauxlib.h"
1420#if __has_include (< luajit .h > )
1521#include <luajit.h>
1622#endif
1723};
24+ #endif
1825
19- /* Compatibility layer for compiling with Lua 5.1 or LuaJIT */
20- #if LUA_VERSION_NUM == 501
26+ #if defined ELUNA_LUAU
27+ #define lua_pushglobaltable (L ) lua_pushvalue((L), LUA_GLOBALSINDEX)
28+ #define lua_rawlen (L , idx ) lua_objlen((L), (idx))
29+
30+ #undef lua_pushcfunction
31+ #undef lua_pushcclosure
32+ #define lua_pushcfunction (L , fn ) lua_pushcclosurek((L), (fn), nullptr, 0, nullptr)
33+ #define lua_pushcclosure (L , fn , nup ) lua_pushcclosurek((L), (fn), nullptr, (nup), nullptr)
34+
35+ // Preserve Lua's expression-style error API used by existing bindings.
36+ #undef luaL_error
37+ #undef luaL_argerror
38+ #define luaL_error (...) (luaL_errorL(__VA_ARGS__), 0)
39+ #define luaL_argerror (L , arg , msg ) (luaL_argerrorL((L), (arg), (msg)), 0)
40+ #define lua_error (L ) (lua_error(L), 0)
41+
42+ int luaL_ref (lua_State * L , int table );
43+ void luaL_unref (lua_State * L , int table , int ref );
44+ #endif
45+
46+ #if defined ELUNA_LUAU || LUA_VERSION_NUM == 501
2147 int luaL_getsubtable (lua_State * L , int i , const char * name );
48+ #if !defined LUAJIT_VERSION
49+ void luaL_setfuncs (lua_State * L , const luaL_Reg * functions , int upvalues );
50+ void * luaL_testudata (lua_State * L , int index , const char * tname );
51+ void luaL_setmetatable (lua_State * L , const char * tname );
52+ #endif
53+ #endif
54+
55+ /* Compatibility layer for compiling with Lua 5.1 or LuaJIT */
56+ #if !defined ELUNA_LUAU && LUA_VERSION_NUM == 501
2257 const char * luaL_tolstring (lua_State * L , int idx , size_t * len );
2358 int lua_absindex (lua_State * L , int i );
2459 #define lua_pushglobaltable (L ) \
@@ -30,14 +65,9 @@ extern "C"
3065 #define lua_load (L , buf_read , dec_buf , str , NULL ) \
3166 lua_load(L, buf_read, dec_buf, str)
3267
33- #if !defined LUAJIT_VERSION
34- void * luaL_testudata (lua_State * L , int index , const char * tname );
35- void luaL_setmetatable (lua_State * L , const char * tname );
36- #define luaL_setfuncs (L , l , n ) luaL_register(L, NULL, l)
37- #endif
3868#endif
3969
40- #if LUA_VERSION_NUM > 502
70+ #if !defined ELUNA_LUAU && LUA_VERSION_NUM > 502
4171 #define lua_dump (L , writer , data ) \
4272 lua_dump(L, writer, data, 0)
4373 #define lua_pushunsigned (L , u ) \
0 commit comments