In lua you can
require a file which basically means that it will read the file and execute it as a function. To do this you can do
If your file is in the folder "
src" you would do
You can also use it as a module, doing this in the
otherluafile.lua
Code: Select all
local mytable = {
func = function (t)
print("Hello "..t.."! this is my great module")
end,
a = "HELLO WORLD"
}
return mytable
then in your main.lua you would do
Code: Select all
print(mytable) --nil
local mytable = require "src.otherluafile"
mytable.func("natev") --Hello natev! this is my great module
print(mytable.a) --HELLO WORLD
This is prefered, since locals dont spread across everywhere as globals do... but dont bother about this right now
NOTE: All the files should be next to your
main.lua file, they could be in folders but those folders should be next to the
main.lua, in the example above the directories inside the .love file should look like this
And all that should be inside the .love file.
If you want to run files from other directory, outside of the .love file then I shall tell you that it's trickier and not safe (it's possible though), but this should be enough to help you with what you asked for