From 3278ea55809729d2aef5be95ca6cdad99c1dfe14 Mon Sep 17 00:00:00 2001 From: Bart van Strien Date: Mon, 25 Sep 2017 10:27:12 +0200 Subject: [PATCH] Fix compilation with lua 5.2 and 5.3 Mostly to have the lua53 "library" work with both lua 5.1 and lua 5.3. Additionally fixes two other incompatibilities. --HG-- branch : minor --- src/common/runtime.cpp | 2 +- src/libraries/lua53/lstrlib.c | 19 +++++++++++++++++-- src/modules/audio/wrap_Audio.cpp | 2 +- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/common/runtime.cpp b/src/common/runtime.cpp index a655462db..883f05e44 100644 --- a/src/common/runtime.cpp +++ b/src/common/runtime.cpp @@ -135,7 +135,7 @@ int luax_traceback(lua_State *L) if (!lua_isstring(L, 1)) // 'message' not a string? return 1; // keep it intact - lua_getfield(L, LUA_GLOBALSINDEX, "debug"); + lua_getglobal(L, "debug"); if (!lua_istable(L, -1)) { lua_pop(L, 1); diff --git a/src/libraries/lua53/lstrlib.c b/src/libraries/lua53/lstrlib.c index 1006bb50a..03f574f18 100755 --- a/src/libraries/lua53/lstrlib.c +++ b/src/libraries/lua53/lstrlib.c @@ -69,10 +69,18 @@ #include "lualib.h" #include "lstrlib.h" +#if LUA_VERSION_NUM == 501 typedef size_t lua_Unsigned; +#endif +#if LUA_VERSION_NUM == 501 +# define LUAL_BUFFER53_BUFFER(B) (B)->b.buffer +#else +# define LUAL_BUFFER53_BUFFER(B) (B)->b.initb +#endif static void luaL_buffinit_53 (lua_State *L, luaL_Buffer_53 *B) { +#if LUA_VERSION_NUM == 501 /* make it crash if used via pointer to a 5.1-style luaL_Buffer */ B->b.p = NULL; B->b.L = NULL; @@ -82,10 +90,14 @@ static void luaL_buffinit_53 (lua_State *L, luaL_Buffer_53 *B) { B->capacity = LUAL_BUFFERSIZE; B->nelems = 0; B->L2 = L; +#else + return luaL_buffinit(L, (luaL_Buffer*) B); +#endif } static char *luaL_prepbuffsize_53 (luaL_Buffer_53 *B, size_t s) { +#if LUA_VERSION_NUM == 501 if (B->capacity - B->nelems < s) { /* needs to grow */ char* newptr = NULL; size_t newcap = B->capacity * 2; @@ -101,6 +113,9 @@ static char *luaL_prepbuffsize_53 (luaL_Buffer_53 *B, size_t s) { B->capacity = newcap; } return B->ptr+B->nelems; +#else + return luaL_prepbuffsize((luaL_Buffer*) B, s); +#endif } @@ -120,12 +135,12 @@ static void luaL_addlstring_53 (luaL_Buffer_53 *B, const char *s, size_t l) { void lua53_pushresult (luaL_Buffer_53 *B) { lua_pushlstring(B->L2, B->ptr, B->nelems); - if (B->ptr != B->b.buffer) + if (B->ptr != LUAL_BUFFER53_BUFFER(B)) lua_replace(B->L2, -2); /* remove userdata buffer */ } void lua53_cleanupbuffer (luaL_Buffer_53 *B) { - if (B->ptr != B->b.buffer) + if (B->ptr != LUAL_BUFFER53_BUFFER(B)) lua_replace(B->L2, -1); /* remove userdata buffer */ } diff --git a/src/modules/audio/wrap_Audio.cpp b/src/modules/audio/wrap_Audio.cpp index 97d2dfa03..b20d897a7 100644 --- a/src/modules/audio/wrap_Audio.cpp +++ b/src/modules/audio/wrap_Audio.cpp @@ -102,7 +102,7 @@ static std::vector readSourceList(lua_State *L, int n) if (n < 0) n += lua_gettop(L) + 1; - int items = (int) lua_objlen(L, n); + int items = (int) luax_objlen(L, n); std::vector sources(items); for (int i = 0; i < items; i++)