SuperCheezGi
SuperCheezGi

Reputation: 879

How do I run another script from inside Lua?

I need to execute a Lua script from inside another Lua script. How many ways are there, and how do I use them?

Upvotes: 23

Views: 43712

Answers (1)

SuperCheezGi
SuperCheezGi

Reputation: 879

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! <newline>

Notice that you do not use the .lua extension when using require(), but you DO need it for dofile(). More information here if needed.

Upvotes: 32

Related Questions