diff options
author | Sam Gross <colesbury@gmail.com> | 2015-11-17 04:24:02 +0300 |
---|---|---|
committer | Sam Gross <colesbury@gmail.com> | 2015-11-17 04:24:02 +0300 |
commit | 79c7dca0587f39059519bee81e341ff126eea4bd (patch) | |
tree | e7956943759ff4d683cc0ee072814367eb5047c2 | |
parent | c5c3e0ea029534bd6dba20a2d0e605fbff98d961 (diff) |
Fixes for Lua 5.1
-rw-r--r-- | ffi.c | 5 | ||||
-rw-r--r-- | ffi.h | 2 | ||||
-rw-r--r-- | test.lua | 29 |
3 files changed, 30 insertions, 6 deletions
@@ -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; @@ -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 @@ -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;};" |