如何从Lua内部运行另一个脚本? [英] How do I run another script from inside Lua?
本文介绍了如何从Lua内部运行另一个脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要从另一个Lua脚本内部执行一个Lua脚本.有多少种方法,我该如何使用它们?
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")
但是您可以通过require()
很好地做到这一点.示例:
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("!")
这将产生输出:
Hello, World! <newline>
请注意,使用require()
时不使用.lua
扩展名,但是dofile()
确实需要它.
如果需要,请此处.
Notice that you do not use the .lua
extension when using require()
, but you DO need it for dofile()
.
More information here if needed.
这篇关于如何从Lua内部运行另一个脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文