mirror of
https://github.com/love2d/love.git
synced 2026-08-12 08:30:56 +02:00
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
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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 */
|
||||
}
|
||||
|
||||
|
||||
@@ -102,7 +102,7 @@ static std::vector<Source*> 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<Source*> sources(items);
|
||||
|
||||
for (int i = 0; i < items; i++)
|
||||
|
||||
Reference in New Issue
Block a user