Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我在 Lua 中有这个问题,我有 2 个文件。FileA 可能如下所示:
require "FileB" local function foo(bar) -- random stuff end
FileB 看起来像这样
foo(bar)
但是会弹出一个错误,说这foo是一个无效的功能。有什么解决办法吗?
foo
通常的做法是将函数放在所需的文件中,而不是调用代码中。
在任何情况下,因为您有上面的代码,所以您在定义它之前调用了 foo 。所以把require移到foo的定义下面,不要用local。
function foo(bar) -- random stuff end require "FileB"