Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/facebook/luaffifb.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Gross <colesbury@gmail.com>2016-01-02 04:20:44 +0300
committerSam Gross <colesbury@gmail.com>2016-01-02 04:26:16 +0300
commitd806f1ae30af77b2024d6c76868298db1b2980bc (patch)
tree92aea67ff0fbc68f9926a900b4fbd0f3f797f1fd
parent79c7dca0587f39059519bee81e341ff126eea4bd (diff)
Add support for Lua 5.3
-rw-r--r--.travis.yml1
-rw-r--r--call.c4
-rw-r--r--ffi.c37
-rw-r--r--ffi.h4
-rw-r--r--parser.c8
-rw-r--r--test.lua22
6 files changed, 42 insertions, 34 deletions
diff --git a/.travis.yml b/.travis.yml
index 291721a..819ddd2 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -13,6 +13,7 @@ os:
env:
- LUA_VERSION=LUA51
- LUA_VERSION=LUA52
+ - LUA_VERSION=LUA53
before_install:
- export PATH="$TRAVIS_BUILD_DIR/install/bin:$PATH"
diff --git a/call.c b/call.c
index f8fb865..7a44b09 100644
--- a/call.c
+++ b/call.c
@@ -14,10 +14,10 @@ static void* reserve_code(struct jit* jit, lua_State* L, size_t sz);
static void commit_code(struct jit* jit, void* p, size_t sz);
static void push_int(lua_State* L, int val)
-{ lua_pushnumber(L, val); }
+{ lua_pushinteger(L, val); }
static void push_uint(lua_State* L, unsigned int val)
-{ lua_pushnumber(L, val); }
+{ lua_pushinteger(L, val); }
static void push_float(lua_State* L, float val)
{ lua_pushnumber(L, val); }
diff --git a/ffi.c b/ffi.c
index eec24a0..eb8462a 100644
--- a/ffi.c
+++ b/ffi.c
@@ -967,7 +967,7 @@ static void set_struct(lua_State* L, int idx, void* to, int to_usr, const struct
sz = lua_rawlen(L, to_usr);
for (i = 2; i < sz; i++) {
- lua_pushnumber(L, i);
+ lua_pushinteger(L, i);
off = get_member(L, to_usr, tt, &mt);
assert(off >= 0);
set_value(L, -2, (char*) to + off, -1, &mt, check_pointers);
@@ -1329,7 +1329,7 @@ static int ffi_sizeof(lua_State* L)
struct ctype ct;
check_ctype(L, 1, &ct);
get_variable_array_size(L, 2, &ct);
- lua_pushnumber(L, ctype_size(L, &ct));
+ lua_pushinteger(L, ctype_size(L, &ct));
return 1;
}
@@ -1341,7 +1341,7 @@ static int ffi_alignof(lua_State* L)
/* if no member is specified then we return the alignment of the type */
if (lua_isnil(L, 2)) {
- lua_pushnumber(L, ct.align_mask + 1);
+ lua_pushinteger(L, ct.align_mask + 1);
return 1;
}
@@ -1352,7 +1352,7 @@ static int ffi_alignof(lua_State* L)
return luaL_error(L, "type %s has no member %s", lua_tostring(L, -1), lua_tostring(L, 2));
}
- lua_pushnumber(L, mt.align_mask + 1);
+ lua_pushinteger(L, mt.align_mask + 1);
return 1;
}
@@ -1370,14 +1370,14 @@ static int ffi_offsetof(lua_State* L)
return luaL_error(L, "type %s has no member %s", lua_tostring(L, -1), lua_tostring(L, 2));
}
- lua_pushnumber(L, off);
+ lua_pushinteger(L, off);
if (!mt.is_bitfield) {
return 1;
}
- lua_pushnumber(L, mt.bit_offset);
- lua_pushnumber(L, mt.bit_size);
+ lua_pushinteger(L, mt.bit_offset);
+ lua_pushinteger(L, mt.bit_size);
return 3;
}
@@ -1570,6 +1570,9 @@ int push_user_mt(lua_State* L, int ct_usr, const struct ctype* ct)
if (ct->type != STRUCT_TYPE && ct->type != UNION_TYPE && !IS_COMPLEX(ct->type)) {
return 0;
}
+ if (!lua_istable(L, ct_usr)) {
+ return 0;
+ }
ct_usr = lua_absindex(L, ct_usr);
lua_pushlightuserdata(L, &user_mt_key);
@@ -1807,7 +1810,7 @@ err:
uint64_t val = *(uint64_t*) data;
val >>= ct.bit_offset;
val &= (UINT64_C(1) << ct.bit_size) - 1;
- lua_pushnumber(L, val);
+ lua_pushinteger(L, val);
return 1;
}
@@ -1861,14 +1864,14 @@ err:
lua_pushboolean(L, *(_Bool*) data);
break;
case INT8_TYPE:
- lua_pushnumber(L, ct.is_unsigned ? (lua_Number) *(uint8_t*) data : (lua_Number) *(int8_t*) data);
+ lua_pushinteger(L, ct.is_unsigned ? (lua_Integer) *(uint8_t*) data : (lua_Integer) *(int8_t*) data);
break;
case INT16_TYPE:
- lua_pushnumber(L, ct.is_unsigned ? (lua_Number) *(uint16_t*) data : (lua_Number) *(int16_t*) data);
+ lua_pushinteger(L, ct.is_unsigned ? (lua_Integer) *(uint16_t*) data : (lua_Integer) *(int16_t*) data);
break;
case ENUM_TYPE:
case INT32_TYPE:
- lua_pushnumber(L, ct.is_unsigned ? (lua_Number) *(uint32_t*) data : (lua_Number) *(int32_t*) data);
+ lua_pushinteger(L, ct.is_unsigned ? (lua_Integer) *(uint32_t*) data : (lua_Integer) *(int32_t*) data);
break;
case INT64_TYPE:
to = push_cdata(L, -1, &ct);
@@ -2592,10 +2595,10 @@ static int ffi_errno(lua_State* L)
struct jit* jit = get_jit(L);
if (!lua_isnoneornil(L, 1)) {
- lua_pushnumber(L, jit->last_errno);
+ lua_pushinteger(L, jit->last_errno);
jit->last_errno = luaL_checknumber(L, 1);
} else {
- lua_pushnumber(L, jit->last_errno);
+ lua_pushinteger(L, jit->last_errno);
}
return 1;
@@ -2625,7 +2628,7 @@ static int ffi_number(lua_State* L)
void* data = to_cdata(L, 1, &ct);
if (ct.type != INVALID_TYPE) {
- lua_pushnumber(L, check_intptr(L, 1, data, &ct));
+ lua_pushinteger(L, check_intptr(L, 1, data, &ct));
return 1;
} else {
/* call the old _G.tonumber, we use an upvalue as _G.tonumber is set
@@ -2939,16 +2942,16 @@ static int cmodule_index(lua_State* L)
return 1;
case INT8_TYPE:
- lua_pushnumber(L, ct.is_unsigned ? (lua_Number) *(uint8_t*) sym : (lua_Number) *(int8_t*) sym);
+ lua_pushinteger(L, ct.is_unsigned ? (lua_Integer) *(uint8_t*) sym : (lua_Integer) *(int8_t*) sym);
return 1;
case INT16_TYPE:
- lua_pushnumber(L, ct.is_unsigned ? (lua_Number) *(uint16_t*) sym : (lua_Number) *(int16_t*) sym);
+ lua_pushinteger(L, ct.is_unsigned ? (lua_Integer) *(uint16_t*) sym : (lua_Integer) *(int16_t*) sym);
return 1;
case INT32_TYPE:
case ENUM_TYPE:
- lua_pushnumber(L, ct.is_unsigned ? (lua_Number) *(uint32_t*) sym : (lua_Number) *(int32_t*) sym);
+ lua_pushinteger(L, ct.is_unsigned ? (lua_Integer) *(uint32_t*) sym : (lua_Integer) *(int32_t*) sym);
return 1;
}
diff --git a/ffi.h b/ffi.h
index ef00fa7..2bca60a 100644
--- a/ffi.h
+++ b/ffi.h
@@ -105,6 +105,10 @@ static char* luaL_prepbuffsize(luaL_Buffer* B, size_t sz) {
}
return luaL_prepbuffer(B);
}
+#elif LUA_VERSION_NUM == 503
+static void (lua_remove)(lua_State *L, int idx) {
+ lua_remove(L, idx);
+}
#endif
/* architectures */
diff --git a/parser.c b/parser.c
index a7c53df..78622f9 100644
--- a/parser.c
+++ b/parser.c
@@ -295,14 +295,14 @@ static int parse_enum(lua_State* L, struct parser* P, struct ctype* type)
/* add the enum value to the constants table */
push_upval(L, &constants_key);
lua_pushvalue(L, -2);
- lua_pushnumber(L, value);
+ lua_pushinteger(L, value);
lua_rawset(L, -3);
lua_pop(L, 1);
assert(lua_gettop(L) == ct_usr + 1);
/* add the enum value to the enum usr value table */
- lua_pushnumber(L, value);
+ lua_pushinteger(L, value);
lua_rawset(L, ct_usr);
if (tok.type == TOK_CLOSE_CURLY) {
@@ -2110,9 +2110,9 @@ static int parse_root(lua_State* L, struct parser* P)
case INT16_TYPE:
case INT32_TYPE:
if (at.is_unsigned)
- lua_pushnumber(L, (unsigned int) val);
+ lua_pushinteger(L, (unsigned int) val);
else
- lua_pushnumber(L, (int) val);
+ lua_pushinteger(L, (int) val);
break;
default:
diff --git a/test.lua b/test.lua
index f14abfb..6e3a608 100644
--- a/test.lua
+++ b/test.lua
@@ -32,11 +32,11 @@ if ffi.arch == 'x86' and ffi.os == 'Windows' then
dlls.__fastcall = ffi.load('test_fastcall')
end
-local function check(a, b)
+local function check(a, b, msg)
if a ~= b then
print('check', a, b)
end
- return _G.assert(a == b)
+ return _G.assert(a == b, msg)
end
print('Running test')
@@ -300,8 +300,8 @@ local test_values = {
uint64_t = 12345678901234,
bool = true,
_Bool = false,
- ['float complex'] = 3+4*i,
- ['double complex'] = 5+6*i,
+ ['float complex'] = 3.1+4.2*i,
+ ['double complex'] = 5.1+6.2*i,
['enum e8'] = ffi.C.FOO8,
['enum e16'] = ffi.C.FOO16,
['enum e32'] = ffi.C.FOO32,
@@ -324,10 +324,10 @@ local types = {
local buf = ffi.new('char[256]')
-local function checkbuf(type, ret)
+local function checkbuf(type, ret, msg)
local str = tostring(test_values[type]):gsub('^cdata%b<>: ', '')
- check(ffi.string(buf), str)
- check(ret, #str)
+ check(ffi.string(buf), str, msg)
+ check(ret, #str, msg)
end
local function checkalign(type, v, ret)
@@ -444,7 +444,7 @@ for convention,c in pairs(dlls) do
for suffix, type in pairs(types) do
local test = test_values[type]
--print('checkbuf', suffix, type, buf, test)
- checkbuf(type, c['print_' .. suffix](buf, test))
+ checkbuf(type, c['print_' .. suffix](buf, test), suffix)
if first then
ffi.cdef(align:gsub('SUFFIX', suffix):gsub('TYPE', type):gsub('ALIGN', 0))
@@ -737,9 +737,9 @@ if _VERSION ~= 'Lua 5.1' then
check(#vls, 5)
end
-check(tostring(1+3*i), '1+3i')
-check(tostring((1+3*i)*(2+4*i)), '-10+10i')
-check(tostring((3+2*i)*(3-2*i)), '13+0i')
+check(tostring(1.1+3.2*i), '1.1+3.2i')
+check((1+3*i)*(2+4*i), -10+10*i)
+check((3+2*i)*(3-2*i), 13+0*i)
-- Should ignore unknown attributes
ffi.cdef [[