Cannot install FFI library for Lua/LuaJIT

2k views Asked by At

I have already correctly installed Lua, LuaJIT and Luarocks (I can run each of them in the terminal without any errors too). I'm trying to run the command luarocks install luaffi but it is returning an error

Error: No results matching query were found for Lua 5.4
To check if it is available for other Lua versions, use --check-lua-versions.

So I tried running luarocks install luaffi --check-lua-versions which also returns the following:

Checking if available for other Lua versions...
Checking for Lua 5.1...
Checking for Lua 5.2...
Checking for Lua 5.3...

Error: No results matching query were found for Lua 5.4.
luaffi is not available for any Lua versions.  "

I'm completely lost, I cannot use ffi in my code because of this (It returns module "ffi" not found).

3

There are 3 answers

0
koyaanisqatsi On

After the build (See: https://github.com/zhaozg/lua-ffi ) you can use Lua 5.1 to test it.

€ cat luajit_sleep.lua 
--[[
Lua JIT ffi Example - Implementing a Lua sleep() function from C
]]
  local ffi = require("ffi")
  ffi.cdef[[void Sleep(int ms); int poll(struct pollfd *fds, unsigned long nfds, int timeout);]]
  local sleep
  if ffi.os == "Windows" then
    function sleep(s) ffi.C.Sleep(s*1000) end
  else
    function sleep(s) ffi.C.poll(nil, 0, s*1000) end
  end

return sleep
€ /bin/lua
Lua 5.1.5  Copyright (C) 1994-2012 Lua.org, PUC-Rio
> sleep = require('luajit_sleep')
> sleep(1) -- CPU friendly sleep() function :-)

It uses (lsof | grep lua)...

/usr/local/lib/lua/5.1/ffi.so

EDIT - Found the Command to install: https://luarocks.org/modules/colesbury/luaffi
Do: luarocks install --server=https://luarocks.org/dev luaffi --verbose
Also goes to...

os.execute:     chmod '0755' '/usr/local/lib/lua/5.1/ffi.so'
Results: 1
  1 (number): 0
luaffi scm-1 is now installed in /usr/local (license: BSD)
0
João Paulo On

cffi-lua is what you are looking for. It is compatible with LuaJIT and Lua >= 5.1

$ luarocks install cffi-lua
0
AllenFang On

If you are mac os user (My case is M2)

try this: https://github.com/zhaozg/lua-ffi

git clone https://github.com/facebook/luaffifb
cd luaffifb
luarocks make