尝试在Ubuntu 10.04上使用LuaFileSystem。

我使用命令 luarocks install luafilesystem 安装了 LuaFileSystem。现在我想在我的脚本中使用它,但是我收到以下错误信息:

[splay.sandbox] W: 要求 lfs 被拒绝 10:34:11.65 (6) [splay.events] E: thread: 0x93f0b20 DIE (error: [string "job code"]:35: 尝试索引局部变量 'lfs'(一个空值)) 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>

我尝试使用全局声明:lfs = require"lfs",也尝试了只使用 require"lfs",甚至在函数中使用本地声明:

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

    print(lfs.currentdir())
end

但是我仍然收到那个错误信息。还有其他需要做的事情才能使它工作吗?

后来编辑:当我尝试使用 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: 尝试索引局部变量 'f'(一个空值))

可能是什么问题?

点赞
用户2458544
用户2458544

可以通过在 io.open 周围添加 assert 来轻松调试。当 io.open 无法打开文件时,将会打印错误消息:

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

这个“技巧”也在以下链接中描述: http://www.lua.org/pil/21.2.html

2013-06-09 19:59:19