无法安装 Lua/LuaJIT 的 FFI 库

问题描述 投票:0回答:2

我已经正确安装了 Lua、LuaJIT 和 Luarocks(我也可以在终端中运行它们,没有任何错误)。我正在尝试运行命令

luarocks install luaffi
但它返回错误

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.

所以我尝试运行

luarocks install luaffi --check-lua-versions
它也返回以下内容:

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

我完全迷失了,因此我无法在代码中使用

ffi
(它返回未找到模块“ffi”)。

lua ffi luajit luarocks
2个回答
1
投票

构建完成后(参见:https://github.com/zhaozg/lua-ffi)你可以使用Lua 5.1来测试它。

€ 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 :-)

它使用(

lsof | grep lua
)...

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

编辑 - 找到要安装的命令:https://luarocks.org/modules/colesbury/luaffi
做:

luarocks install --server=https://luarocks.org/dev luaffi --verbose

还去...

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
投票

cffi-lua 就是您正在寻找的。它与 LuaJIT 和 Lua >= 5.1 兼容

$ luarocks install cffi-lua
最新问题
© www.soinside.com 2019 - 2024. All rights reserved.