diff options
Diffstat (limited to 'c-api/compat-5.3.h')
-rw-r--r-- | c-api/compat-5.3.h | 38 |
1 files changed, 35 insertions, 3 deletions
diff --git a/c-api/compat-5.3.h b/c-api/compat-5.3.h index bee77a1..755c23e 100644 --- a/c-api/compat-5.3.h +++ b/c-api/compat-5.3.h @@ -9,11 +9,13 @@ extern "C" { #endif #include <lua.h> #include <lauxlib.h> +#include <lualib.h> #if defined(__cplusplus) && !defined(COMPAT53_LUA_CPP) } #endif +#undef COMPAT53_INCLUDE_SOURCE #if defined(COMPAT53_PREFIX) /* - change the symbol names of functions to avoid linker conflicts * - compat-5.3.c needs to be compiled (and linked) separately @@ -21,7 +23,6 @@ extern "C" { # if !defined(COMPAT53_API) # define COMPAT53_API extern # endif -# undef COMPAT53_INCLUDE_SOURCE #else /* COMPAT53_PREFIX */ /* - make all functions static and include the source. * - compat-5.3.c doesn't need to be compiled (and linked) separately @@ -50,8 +51,6 @@ extern "C" { * lua_upvaluejoin * lua_version * lua_yieldk - * luaL_loadbufferx - * luaL_loadfilex */ #ifndef LUA_OK @@ -88,6 +87,19 @@ extern "C" { # define LUA_OPLE 2 #endif +/* LuaJIT/Lua 5.1 does not have the updated + * error codes for thread status/function returns (but some patched versions do) + * define it only if it's not found + */ +#if !defined(LUA_ERRGCMM) +/* Use + 2 because in some versions of Lua (Lua 5.1) + * LUA_ERRFILE is defined as (LUA_ERRERR+1) + * so we need to avoid it (LuaJIT might have something at this + * integer value too) + */ +# define LUA_ERRGCMM (LUA_ERRERR + 2) +#endif /* LUA_ERRGCMM define */ + typedef size_t lua_Unsigned; typedef struct luaL_Buffer_53 { @@ -99,6 +111,14 @@ typedef struct luaL_Buffer_53 { } luaL_Buffer_53; #define luaL_Buffer luaL_Buffer_53 +/* In PUC-Rio 5.1, userdata is a simple FILE* + * In LuaJIT, it's a struct where the first member is a FILE* + * We can't support the `closef` member + */ +typedef struct luaL_Stream { + FILE *f; +} luaL_Stream; + #define lua_absindex COMPAT53_CONCAT(COMPAT53_PREFIX, _absindex) COMPAT53_API int lua_absindex (lua_State *L, int i); @@ -154,6 +174,15 @@ COMPAT53_API lua_Number lua_tonumberx (lua_State *L, int i, int *isnum); #define luaL_checkversion COMPAT53_CONCAT(COMPAT53_PREFIX, L_checkversion) COMPAT53_API void luaL_checkversion (lua_State *L); +#define lua_load COMPAT53_CONCAT(COMPAT53_PREFIX, _load_53) +COMPAT53_API int lua_load (lua_State *L, lua_Reader reader, void *data, const char* source, const char* mode); + +#define luaL_loadfilex COMPAT53_CONCAT(COMPAT53_PREFIX, L_loadfilex) +COMPAT53_API int luaL_loadfilex (lua_State *L, const char *filename, const char *mode); + +#define luaL_loadbufferx COMPAT53_CONCAT(COMPAT53_PREFIX, L_loadbufferx) +COMPAT53_API int luaL_loadbufferx (lua_State *L, const char *buff, size_t sz, const char *name, const char *mode); + #define luaL_checkstack COMPAT53_CONCAT(COMPAT53_PREFIX, L_checkstack_53) COMPAT53_API void luaL_checkstack (lua_State *L, int sp, const char *msg); @@ -186,6 +215,9 @@ COMPAT53_API int luaL_execresult (lua_State *L, int stat); #define lua_pcallk(L, na, nr, err, ctx, cont) \ ((void)(ctx), (void)(cont), lua_pcall((L), (na), (nr), (err))) +#define lua_resume(L, from, nargs) \ + ((void)(from), lua_resume((L), (nargs))) + #define luaL_buffinit COMPAT53_CONCAT(COMPAT53_PREFIX, _buffinit_53) COMPAT53_API void luaL_buffinit (lua_State *L, luaL_Buffer_53 *B); |