LuaJIT's FFI not working?

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
EpichinoM2
Prole
Posts: 2
Joined: Mon Jun 25, 2018 12:32 pm

LuaJIT's FFI not working?

Post by EpichinoM2 » Sun Mar 10, 2019 2:16 am

I'm using ZeroBrane as an IDE. When I select Lua as the interpreter, then hit execute on the file main.lua:

Code: Select all

os.execute([[gcc -shared -fPIC -o libtest.so test.c]])

local ffi = require"ffi"
local ltest = ffi.load"./libtest.so"

ffi.cdef[[
int ret();
]]

print(ltest.ret())
where test.c is:

Code: Select all

int ret(){
    return 124;
}
Then 124 just gets printed out, as expected. But if I select LÖVE as the interpreter, I get an error:

Code: Select all

Error: main.lua:4: cannot load module './libtest.so': %1 is not a valid Win32 application.
This seems to be the same for 0.10.2 and 11.1 . I thought that since LÖVE already uses LuaJIT, there shouldn't be problems like this, but maybe it's ZB's fault?

User avatar
pgimeno
Party member
Posts: 2168
Joined: Sun Oct 18, 2015 2:58 pm

Re: LuaJIT's FFI not working?

Post by pgimeno » Sun Mar 10, 2019 3:13 am

Hi, welcome to the forums!

Could it be a bits mismatch? I mean in the 32 vs 64 sense. Perhaps love and lua are compiled for a different number of bits?

User avatar
arampl
Party member
Posts: 248
Joined: Mon Oct 20, 2014 3:26 pm

Re: LuaJIT's FFI not working?

Post by arampl » Sun Mar 10, 2019 4:29 am

Hmm. Using *.so library on Windows looks strange for me. Shouldn't you compile as a *.dll?
Also AFAIK to load dynamic library from current directory you should call ffi.load("<your library>", true). At least on Linux.

EDIT: Sorry, my statement about ffi.load "global" flag was incorrect. It has nothing to do with loading from current directory.

EpichinoM2
Prole
Posts: 2
Joined: Mon Jun 25, 2018 12:32 pm

Re: LuaJIT's FFI not working?

Post by EpichinoM2 » Sun Mar 10, 2019 12:32 pm

pgimeno wrote:
Sun Mar 10, 2019 3:13 am
Hi, welcome to the forums!

Could it be a bits mismatch? I mean in the 32 vs 64 sense. Perhaps love and lua are compiled for a different number of bits?
Yeah, I downloaded a 32bit version of LÖVE and it seems to be working fine now, thanks :) .

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 12 guests