require函数无法看到模块文件

时间:2018-03-19 14:33:53

标签: lua

所以这是我的kek13 lua chunk文件:

-- modules
-- a package is a collection of modules

local test = {}

function test.add(n1, n2) -- dont put local as the scope of this function 
since you already added
-- a local to the 'test' table... doing so will return an error
return n1 + n2
end

function test.hi(name)
return "my name is " .. name
end

return test

..这是我的kek13Part2Real lua chunk文件:

 print("===========================")

 local dad = require("kek13")

 print(dad.hi("A"))

 print(dad.add(1, 5))

 print("==============================")

 require ("kek13")

 print(dad.hi("ur mum"))
 print(dad.add(2, 2))

 print("========================================")

它们位于同一文件夹中,至少在文档文件夹中。 唯一的问题是这会导致错误。像lua这样的东西无法找到或看到文件。顺便说一下,我正在使用Zerobrane IDE。

1 个答案:

答案 0 :(得分:1)

require不检查调用脚本所在的文件夹。

dofile与路径一起使用,或将包含所需脚本的文件夹添加到LUA_PATH环境变量中,或将其附加到package.path

这不是必须如何工作。请阅读手册......

https://www.lua.org/manual/5.3/manual.html#pdf-require

相关问题