Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I run another script from inside Lua?

Tags:

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

like image 551
SuperCheezGi Avatar asked Jan 07 '13 22:01

SuperCheezGi


People also ask

How do I add Lua scripts?

With the Entity Inspector view pane visible, select the entity in the viewport. Click Add Component, and then open Scripting, Lua Script. Scroll down to the Scripting section, and then click Lua Script. A Lua Script component appears in the inspector.


1 Answers

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.

like image 66
SuperCheezGi Avatar answered Sep 20 '22 19:09

SuperCheezGi