【发布时间】:2014-07-23 11:10:34
【问题描述】:
没有成功,我尝试使用 require 关键字将自己的 Lua 文件导入其他脚本,但每当我尝试调用导入模块中包含的任何函数(例如“test.lua”)时,我都会遇到以下错误:
require 'test'
test.method(args)
==> yields error:
==> Attempt to index global 'test' (a nil value)
我已将文件添加到 package.path 以防万一这是问题,但同样没有开始错误表明它无法在 Lua 的路径中找到该文件。
package.path = package.path .. ";/path/to/test.lua"
require 'test'
test.method(args)
==> yields error:
==> Attempt to index global 'test' (a nil value)
我正在从文件所在的目录运行交互式 Lua shell。尝试打印局部变量名称时,例如local test = 要求 "test" 值为 nil。
package.path = package.path .. ";/path/to/test.lua"
local test = require 'test'
print(test)
==> nil
想法? (注意:我通常还需要该文件,但没有将其分配给局部变量,并以 nil 作为返回值再次打印其值。)
【问题讨论】:
-
把你的代码放在这里。我们不能心灵感应。
-
更新了,又是一开始就炸了。
标签: lua importerror