[英]How to load Lua-Filesystem and Lua-Penlight in Luaj
I have a program using the Luaj 3.0 libraries and I found some lua scripts I want to include, but they all require lua file system and penlight and whenever I try to use those libraries, it gives an error. 我有一个使用Luaj 3.0库的程序,发现了一些我想包含的lua脚本,但是它们都需要lua文件系统和penlight,并且每当我尝试使用这些库时,都会出错。
Does anyone know how I am supposed to make use of those in Luaj? 有谁知道我应该怎么利用Luaj中的那些东西?
Edit: A little more information might help: I have am Archlinux 64bit system with open-jdk8 Luaj, lua-filesystem, and lua-penlight installed. 编辑:更多信息可能会有所帮助:我安装了带有open-jdk8 Luaj,lua文件系统和lua-penlight的Archlinux 64位系统。 I found a set of libraries called Lua Java Utils which I want to include in my project.
我找到了一组名为Lua Java Utils的库,希望将其包含在项目中。 But it always gets this error:
但它总是会出现此错误:
@luaJavaUtils/import.lua:24 index expected, got nil
Line 24 for reference: 第24行供参考:
local function import_class (classname,packagename)
local res,class = pcall(luajava.bindClass,packagename)
if res then
_G[classname] = class
local mt = getmetatable(class)
mt.__call = call -- <----- Error Here
return class
end
end
It requires the penlight library which in turn requires lua filesystem which is why I installed the two. 它需要penlight库,这又需要lua文件系统,这就是我安装两者的原因。 I found through testing that Lua filesystem wasn't loading by trying to run
lfs.currentdir()
. 通过测试,我发现通过尝试运行
lfs.currentdir()
并没有加载Lua文件系统。 I tried globals.load("local lfs = require \\"lfs\\"").call();
我尝试了
globals.load("local lfs = require \\"lfs\\"").call();
but it also gave an error. 但它也给出了一个错误。
My Lfs library is located at /usr/lib/lua/5.2/lfs.so
and penlight at /usr/share/lua/5.2/pl
. 我的Lfs库位于
/usr/lib/lua/5.2/lfs.so
位于/usr/share/lua/5.2/pl
。
This Is an Issue in the Luaj 3.0 and Luaj 3.0 alpha 1. 这是Luaj 3.0和Luaj 3.0 alpha 1中的一个问题。
The lua package.path is being ignored while requiring a module. lua package.path在需要模块时被忽略。 Here's a workout for this. 这是一个锻炼。
You can override the require function: 您可以覆盖require函数:
local oldReq = require
function require(f)
local fi = io.open(f, "r")
local fs = f
if not fi then
fi = io.open(f .. ".lua", "r")
fs = f .. ".lua"
if not fi then
error("Invalid module " .. f)
return
end
end
local l = loadfile(fs)
if not l then
return oldReq(f)
end
return l()
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.