添加可选的“全局"消息. lua 5.2来源的关键字 [英] Adding an optional "global" keyword to lua 5.2 source

查看:105
本文介绍了添加可选的“全局"消息. lua 5.2来源的关键字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想修改lua 5.2源代码,以允许在全局变量声明之前使用一个可选的"global"关键字.有没有做到这一点,或者有人知道如何(安全地)做到这一点?是的,我知道默认情况下变量是全局变量,这纯粹是语法糖.

I'd like to modify the lua 5.2 source code to allow for an optional "global" keyword to precede global variable declarations. Has any done this or does anyone know how to do this (safely)? And yes I am aware that variables are global by default and that this would be purely syntactic sugar.

很明显,直接添加现有类型的自定义关键字是很简单的.我不知所措的部分是如何安全地(通过5.2 C源代码)编辑解析器,以使其放弃或忽略新的"global"关键字.

To be clear, adding custom keywords of existing types is straight forward. The part I'm at a loss for is how to safely edit the parser (via the 5.2 C source code) so that it discards or ignores the new "global" keyword.

推荐答案

弄清楚了.首先,我在RESERVED枚举的末尾附加了一个新令牌TK_GLOBAL.

Figured it out. First I appended a new token TK_GLOBAL to the end of the RESERVED enum.

然后在luaX_init()中我添加了...

Then in luaX_init() I added...

ts = luaS_new(L, "global");
luaS_fix(ts);
ts->tsv.reserved = cast_byte(TK_GLOBAL+1-FIRST_RESERVED);

最后在我添加的statement()函数中...

And finally in the statement() function I added...

case TK_GLOBAL:
   luaX_next(ls);
break;

据我所知它是可行的.希望它是安全的.

As far as I can tell it works. Hopefully it's safe.

这篇关于添加可选的“全局"消息. lua 5.2来源的关键字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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