Reputation: 35
I have this issue in Lua where I have 2 files. FileA may look like this:
require "FileB"
local function foo(bar)
-- random stuff
end
And FileB looks like this
foo(bar)
But an error pops up, saying that foo
is an invalid function. Is there any fix for this?
Upvotes: 0
Views: 184
Reputation: 2091
Normal practice would be to put the functions in the required file, not the calling code.
In any case as you have your code above, you are calling foo before you are defining it. So move the require below the definition of foo, and don't use local.
function foo(bar)
-- random stuff
end
require "FileB"
Upvotes: 1