How to load Lua-Filesystem and Lua-Penlight in Luaj

707 Views Asked by At

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.

Does anyone know how I am supposed to make use of those in Luaj?

Edit: A little more information might help: I have am Archlinux 64bit system with open-jdk8 Luaj, lua-filesystem, and lua-penlight installed. I found a set of libraries called Lua Java Utils which I want to include in my project. But it always gets this error:

@luaJavaUtils/import.lua:24 index expected, got nil

Line 24 for reference:

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. I found through testing that Lua filesystem wasn't loading by trying to run lfs.currentdir(). I tried 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.

1

There are 1 best solutions below

3
On

This Is an Issue in the Luaj 3.0 and Luaj 3.0 alpha 1.

The lua package.path is being ignored while requiring a module. Here's a workout for this.

You can override the require function:

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