从另一个 Lua 文件加载时如何将参数传递给 Lua 文件? [英] How can I pass parameters to a Lua file when loading it from another Lua file?

查看:13
本文介绍了从另一个 Lua 文件加载时如何将参数传递给 Lua 文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一些帮助来解析 lua 文件的命令行.我正在执行一个 lua 文件,该 lua 文件有一个命令dofile(2nd.lua-file)",但是,我想通过第一个 lua 文件将一些参数传递给第二个 lua 文件.

I need some help on parsing the Command Line for a lua file. I am executing a lua file and that lua file has a command "dofile(2nd.lua-file)", but, I want to pass some argument to this 2nd lua file through this 1st lua file.

示例-a.lua 有 dofile("b.lua"),现在我必须通过这个 a.lua 向 b.lua 传递一些参数,我该怎么做.

example- a.lua has dofile("b.lua"), and now I have to pass some argument to b.lua through this a.lua and how can I do this.

推荐答案

试试这个.在文件`a.lua'中:

Try this. In file `a.lua':

assert(loadfile("b.lua"))(10,20,30)

在文件b.lua中:

本地 a,b,c=...

本地参数={...}

b.lua 的参数作为可变参数接收,因此 ....

The arguments to b.lua are received as varargs, hence the ....

这篇关于从另一个 Lua 文件加载时如何将参数传递给 Lua 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆