如何为Lua表添加前缀? [英] How to prefix a Lua table?

查看:145
本文介绍了如何为Lua表添加前缀?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个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屋!

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