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>2015-11-17 04:24:02 +0300
committerSam Gross <colesbury@gmail.com>2015-11-17 04:24:02 +0300
commit79c7dca0587f39059519bee81e341ff126eea4bd (patch)
treee7956943759ff4d683cc0ee072814367eb5047c2
parentc5c3e0ea029534bd6dba20a2d0e605fbff98d961 (diff)
Fixes for Lua 5.1
-rw-r--r--ffi.c5
-rw-r--r--ffi.h2
-rw-r--r--test.lua29
3 files changed, 30 insertions, 6 deletions
diff --git a/ffi.c b/ffi.c
index 5890c47..eec24a0 100644
--- a/ffi.c
+++ b/ffi.c
@@ -110,8 +110,13 @@ static void* userdata_toptr(lua_State* L, int idx)
lua_pop(L, 2);
if (isfile) {
+#if LUA_VERSION_NUM == 501
+ FILE** stream = (FILE**) ptr;
+ return *stream;
+#else
luaL_Stream* stream = (luaL_Stream*) ptr;
return stream->f;
+#endif
}
return ptr;
diff --git a/ffi.h b/ffi.h
index ce6401f..ef00fa7 100644
--- a/ffi.h
+++ b/ffi.h
@@ -23,11 +23,13 @@
extern "C" {
# include <lua.h>
# include <lauxlib.h>
+# include <lualib.h>
}
# define EXTERN_C extern "C"
#else
# include <lua.h>
# include <lauxlib.h>
+# include <lualib.h>
# define EXTERN_C extern
#endif
diff --git a/test.lua b/test.lua
index 8472863..f14abfb 100644
--- a/test.lua
+++ b/test.lua
@@ -10,7 +10,22 @@ io.stdout:setvbuf('no')
local ffi = require 'ffi'
local dlls = {}
-dlls.__cdecl = ffi.load(package.searchpath('ffi.libtest', package.cpath))
+local function loadlib(lib)
+ for pattern in package.cpath:gmatch('[^;]+') do
+ local path = pattern:gsub('?', lib)
+ local ok, lib = pcall(ffi.load, path)
+ if ok then
+ return lib
+ end
+ end
+ error("Unable to load", lib)
+end
+
+if _VERSION == 'Lua 5.1' then
+ dlls.__cdecl = loadlib('ffi/libtest')
+else
+ dlls.__cdecl = ffi.load(package.searchpath('ffi.libtest', package.cpath))
+end
if ffi.arch == 'x86' and ffi.os == 'Windows' then
dlls.__stdcall = ffi.load('test_stdcall')
@@ -855,11 +870,13 @@ assert(v.a == 1 and v.b == 2 and v.c == 3)
local tp = ffi.metatype("struct newtest",
{__pairs = function(tp) return tp.a, tp.b end, __ipairs = function(tp) return tp.b, tp.c end}
)
-local v = tp(1, 2, 3)
-x, y = pairs(v)
-assert(x == 1 and y == 2)
-x, y = ipairs(v)
-assert(x == 2 and y == 3)
+if _VERSION ~= 'Lua 5.1' then
+ local v = tp(1, 2, 3)
+ x, y = pairs(v)
+ assert(x == 1 and y == 2)
+ x, y = ipairs(v)
+ assert(x == 2 and y == 3)
+end
-- test for pointer to struct having same metamethods
local st = ffi.cdef "struct ptest {int a, b;};"