0

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).

shafee
  • 15,566
  • 3
  • 19
  • 47
refrain
  • 51
  • 7
  • FFI is only available in LuaJIT and LuaJIT use a Lua 5.1. Did you already read: https://luajit.org/ext_ffi_tutorial.html ? – koyaanisqatsi Dec 25 '22 at 16:19
  • 1
    An FFI library does exist for vanilla Lua, but you should find it and build manually. Maybe Luarocks does not have it. Or use LuaJIT - it includes FFI by default. – Egor Skriptunoff Dec 25 '22 at 16:26
  • OK - I see - Have tried and successfully built it: https://github.com/zhaozg/lua-ffi - It installs also Lua 5.1 when call: ```luarocks make``` – koyaanisqatsi Dec 25 '22 at 16:38

1 Answers1

1

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)
koyaanisqatsi
  • 2,585
  • 2
  • 8
  • 15