1

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.

Thomas
  • 871
  • 2
  • 8
  • 21

1 Answers1

0

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
Community
  • 1
  • 1
111WARLOCK111
  • 153
  • 1
  • 1
  • 9
  • As far as I can tell that bug was fixed. In the thread you linked to they say they fixed that in beta 1 and I looked at the source and it looked like it was using the path. – Thomas Aug 29 '14 at 13:02
  • I tried that and it didn't work. How am I supposed to use require anyway, since whenever I try to call any of these files directly I get an error. – Thomas Aug 29 '14 at 18:51
  • @user2752635 from my looking into LuaJ's official webpage, There's no support for C/C++ libraries, As you've defined above, You're trying to load a UNIX library which is impossible from LuaJ. There's no connection between LuaJ and C API. `Libraries are coded to closely match the behavior specified in See standard lua documentation for details on the library API's` - As looking close into the project, Libraries are made to be just like LuaC API, but not the LuaC it self. Not all libraries of Lua API is available for LuaJ. So sadly there's no way to load OS specified Libraries. – 111WARLOCK111 Aug 30 '14 at 07:30