I need to execute a Lua script from inside another Lua script. How many ways are there, and how do I use them?
Usually you would use the following:
dofile("filename.lua")
But you can do this through require()
nicely. Example:
foo.lua:
io.write("Hello,")
require("bar")
bar.lua:
io.write(" ")
require("baz")
baz.lua:
io.write("World")
require("qux")
qux.lua:
print("!")
This produces the output:
Hello, World!
Notice that you do not use the .lua
extension when using require()
, but you DO need it for dofile()
.
More information here if needed.