如何为Lua表添加前缀? [英] How to prefix a Lua table?
问题描述
我有一个lua文件,其内容为lua表,如下所示:
A={}
,
A.B={}
,
A.B.C=0;
,
I have a lua file whose content is lua Table as below:
A={}
,
A.B={}
,
A.B.C=0;
,
问题是我想在每个以上语句之前添加前缀XYZ.因此,在解析之后,数据库应该对此感到高兴:
XYZ.A={}
,
XYZ.A.B={}
,
XYZ.A.B.C={}
,
The problem is I want to add prefix XYZ before each above statements. So after the parse the database should have something loke this:
XYZ.A={}
,
XYZ.A.B={}
,
XYZ.A.B.C={}
,
有什么想法吗?预先感谢
Any ideas? Thanks in advance
推荐答案
您可以使用环境loadfile("mydata","t",XYZ)
和XYZ
加载文件.参见手册中的 loadfile .
You can load the file with XYZ
as is environment: loadfile("mydata","t",XYZ)
. See loadfile in the manual.
这在Lua 5.2中有效.对于Lua 5.1,请使用loadfile
,然后使用setfenv
.
This works in Lua 5.2. For Lua 5.1, use loadfile
followed by setfenv
.
这篇关于如何为Lua表添加前缀?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!