Search code examples
luarequire

How to make a "requireable" lua script


Hello,

I was wondering, is there any possible way to make a lua script that contains one (or more) functions that you can "return" them, and require with another lua script?

I tried this, but didn't work

Functions

Func = {
function test(a)
 print(a)
end
}
return Func

Main Code

require(FUNCTIONS_PATH)

It gives an error on that point (probably because the code is totally wrong). I would like some help on that.

Thank you.


Solution

  • Separate the name from function, like this:

    Func = {
    test = function(a)
     print(a)
    end
    }
    return Func