Trying to use LuaFileSystem on Ubuntu 10.04

I've installed LuaFileSystem using the command: luarocks install luafilesystem. Now I want to use it in my script but I get this error:

[splay.sandbox] W: Require of lfs refused 10:34:11.65 (6) [splay.events] E: thread: 0x93f0b20 DIE (error: [string "job code"]:35: attempt to index local 'lfs' (a nil value)) 10:34:11.65 (6) [splay.events] E: stack traceback: 10:34:11.65 (6) [string "job code"]:35: in function 'getHomeDirectory' 10:34:11.65 (6) [string "job code"]:79: in function <[string "job code"]:76>

I've tried to declare it global: lfs = require"lfs", or just require"lfs", even local in a function:

function getHomeDirectory(position)
    local lfs = require"lfs"

    print(lfs.currentdir())
end

But still I get that error. There's something that I still have to do to make it work?

LATER EDIT: the same error with "a nil value" I get when trying to open a file with io:

local f = io.open('/home/alex/Desktop/SPLAY WORK/splay_client_commands_1.4/test1.txt', "r")

[splay.events] E: thread: 0x955f4c0 DIE (error: [string "job code"]:120: attempt to index local 'f' (a nil value))

What could be the problem?

Upvotes: 0

Views: 210

Answers (1)

Enigma
Enigma

Reputation: 1717

The io.open call can be easily debugged by adding assert around it. This will print the error message when io.open fails to open the file:

local f = assert(io.open('/home/alex/Desktop/SPLAY WORK/splay_client_commands_1.4/test1.txt', "r"))

This "trick" is also described at: http://www.lua.org/pil/21.2.html

Upvotes: 2

Related Questions