|
15 | 15 | * compilation. |
16 | 16 | */ |
17 | 17 | #define LUA_LIB |
| 18 | +#include <limits.h> |
18 | 19 | #include <stdlib.h> |
19 | 20 | #include <string.h> |
20 | | -#include <limits.h> |
21 | 21 |
|
22 | | -#include <lua.h> |
23 | 22 | #include <lauxlib.h> |
| 23 | +#include <lua.h> |
| 24 | +#include <luaconf.h> |
24 | 25 |
|
25 | 26 | #ifdef MPACK_USE_AMALGAMATION |
26 | 27 | # define MPACK_API static |
|
34 | 35 | #define SESSION_META_NAME "mpack.Session" |
35 | 36 | #define NIL_NAME "mpack.NIL" |
36 | 37 |
|
37 | | -#if LUA_VERSION_NUM > 501 |
38 | 38 | /* |
39 | 39 | * TODO(tarruda): When targeting lua 5.3 and being compiled with `long long` |
40 | 40 | * support(not -ansi), we should make use of lua 64 bit integers for |
41 | 41 | * representing msgpack integers, since `double` can't represent the full range. |
42 | 42 | */ |
43 | | -typedef luaL_Reg luaL_reg; |
44 | | -#define luaL_register(L, name, lreg) (luaL_setfuncs((L), (lreg), 0)) |
45 | | -#define lua_objlen(L, idx) (lua_rawlen(L, (idx))) |
| 43 | + |
| 44 | +#ifndef luaL_reg |
| 45 | +/* Taken from Lua5.1's lauxlib.h */ |
| 46 | +#define luaL_reg luaL_Reg |
| 47 | +#endif |
| 48 | + |
| 49 | +#if LUA_VERSION_NUM > 501 |
| 50 | +#define luaL_register(L,n,f) luaL_setfuncs(L,f,0) |
46 | 51 | #endif |
47 | 52 |
|
48 | 53 | typedef struct { |
@@ -198,7 +203,13 @@ static mpack_uint32_t lmpack_objlen(lua_State *L, int *is_array) |
198 | 203 | assert(top = lua_gettop(L)); |
199 | 204 |
|
200 | 205 | if ((type = lua_type(L, -1)) != LUA_TTABLE) { |
| 206 | +#if LUA_VERSION_NUM >= 502 |
| 207 | + len = lua_rawlen(L, -1); |
| 208 | +#elif LUA_VERSION_NUM == 501 |
201 | 209 | len = lua_objlen(L, -1); |
| 210 | +#else |
| 211 | + #error You have either broken or too old Lua installation. This library requires Lua>=5.1 |
| 212 | +#endif |
202 | 213 | goto end; |
203 | 214 | } |
204 | 215 |
|
|
0 commit comments