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 »

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: 3550
Joined: Sun Oct 18, 2015 2:58 pm

Re: LuaJIT's FFI not working?

Post by pgimeno »

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 »

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 »

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: Google [Bot] and 187 guests