diff options
Diffstat (limited to 'c-api')
-rw-r--r-- | c-api/compat-5.3.c | 4 | ||||
-rw-r--r-- | c-api/compat-5.3.h | 24 |
2 files changed, 25 insertions, 3 deletions
diff --git a/c-api/compat-5.3.c b/c-api/compat-5.3.c index 9d63b5d..bd9e277 100644 --- a/c-api/compat-5.3.c +++ b/c-api/compat-5.3.c | |||
@@ -184,11 +184,11 @@ COMPAT53_API void lua_copy (lua_State *L, int from, int to) { | |||
184 | COMPAT53_API void lua_len (lua_State *L, int i) { | 184 | COMPAT53_API void lua_len (lua_State *L, int i) { |
185 | switch (lua_type(L, i)) { | 185 | switch (lua_type(L, i)) { |
186 | case LUA_TSTRING: | 186 | case LUA_TSTRING: |
187 | lua_pushnumber(L, (lua_Integer)lua_objlen(L, i)); | 187 | lua_pushnumber(L, (lua_Number)lua_objlen(L, i)); |
188 | break; | 188 | break; |
189 | case LUA_TTABLE: | 189 | case LUA_TTABLE: |
190 | if (!luaL_callmeta(L, i, "__len")) | 190 | if (!luaL_callmeta(L, i, "__len")) |
191 | lua_pushnumber(L, (lua_Integer)lua_objlen(L, i)); | 191 | lua_pushnumber(L, (lua_Number)lua_objlen(L, i)); |
192 | break; | 192 | break; |
193 | case LUA_TUSERDATA: | 193 | case LUA_TUSERDATA: |
194 | if (luaL_callmeta(L, i, "__len")) | 194 | if (luaL_callmeta(L, i, "__len")) |
diff --git a/c-api/compat-5.3.h b/c-api/compat-5.3.h index af08b6a..c62d6bf 100644 --- a/c-api/compat-5.3.h +++ b/c-api/compat-5.3.h | |||
@@ -9,11 +9,13 @@ extern "C" { | |||
9 | #endif | 9 | #endif |
10 | #include <lua.h> | 10 | #include <lua.h> |
11 | #include <lauxlib.h> | 11 | #include <lauxlib.h> |
12 | #include <lualib.h> | ||
12 | #if defined(__cplusplus) && !defined(COMPAT53_LUA_CPP) | 13 | #if defined(__cplusplus) && !defined(COMPAT53_LUA_CPP) |
13 | } | 14 | } |
14 | #endif | 15 | #endif |
15 | 16 | ||
16 | 17 | ||
18 | #undef COMPAT53_INCLUDE_SOURCE | ||
17 | #if defined(COMPAT53_PREFIX) | 19 | #if defined(COMPAT53_PREFIX) |
18 | /* - change the symbol names of functions to avoid linker conflicts | 20 | /* - change the symbol names of functions to avoid linker conflicts |
19 | * - compat-5.3.c needs to be compiled (and linked) separately | 21 | * - compat-5.3.c needs to be compiled (and linked) separately |
@@ -21,7 +23,6 @@ extern "C" { | |||
21 | # if !defined(COMPAT53_API) | 23 | # if !defined(COMPAT53_API) |
22 | # define COMPAT53_API extern | 24 | # define COMPAT53_API extern |
23 | # endif | 25 | # endif |
24 | # undef COMPAT53_INCLUDE_SOURCE | ||
25 | #else /* COMPAT53_PREFIX */ | 26 | #else /* COMPAT53_PREFIX */ |
26 | /* - make all functions static and include the source. | 27 | /* - make all functions static and include the source. |
27 | * - compat-5.3.c doesn't need to be compiled (and linked) separately | 28 | * - compat-5.3.c doesn't need to be compiled (and linked) separately |
@@ -86,6 +87,19 @@ extern "C" { | |||
86 | # define LUA_OPLE 2 | 87 | # define LUA_OPLE 2 |
87 | #endif | 88 | #endif |
88 | 89 | ||
90 | /* LuaJIT/Lua 5.1 does not have the updated | ||
91 | * error codes for thread status/function returns (but some patched versions do) | ||
92 | * define it only if it's not found | ||
93 | */ | ||
94 | #if !defined(LUA_ERRGCMM) | ||
95 | /* Use + 2 because in some versions of Lua (Lua 5.1) | ||
96 | * LUA_ERRFILE is defined as (LUA_ERRERR+1) | ||
97 | * so we need to avoid it (LuaJIT might have something at this | ||
98 | * integer value too) | ||
99 | */ | ||
100 | # define LUA_ERRGCMM (LUA_ERRERR + 2) | ||
101 | #endif /* LUA_ERRGCMM define */ | ||
102 | |||
89 | typedef size_t lua_Unsigned; | 103 | typedef size_t lua_Unsigned; |
90 | 104 | ||
91 | typedef struct luaL_Buffer_53 { | 105 | typedef struct luaL_Buffer_53 { |
@@ -97,6 +111,14 @@ typedef struct luaL_Buffer_53 { | |||
97 | } luaL_Buffer_53; | 111 | } luaL_Buffer_53; |
98 | #define luaL_Buffer luaL_Buffer_53 | 112 | #define luaL_Buffer luaL_Buffer_53 |
99 | 113 | ||
114 | /* In PUC-Rio 5.1, userdata is a simple FILE* | ||
115 | * In LuaJIT, it's a struct where the first member is a FILE* | ||
116 | * We can't support the `closef` member | ||
117 | */ | ||
118 | typedef struct luaL_Stream { | ||
119 | FILE *f; | ||
120 | } luaL_Stream; | ||
121 | |||
100 | #define lua_absindex COMPAT53_CONCAT(COMPAT53_PREFIX, _absindex) | 122 | #define lua_absindex COMPAT53_CONCAT(COMPAT53_PREFIX, _absindex) |
101 | COMPAT53_API int lua_absindex (lua_State *L, int i); | 123 | COMPAT53_API int lua_absindex (lua_State *L, int i); |
102 | 124 | ||