关于PiL中的一段对_G的描述
lua吧
全部回复
仅看楼主
level 3
chaosink 楼主
PiL146页的第一段:
For Lua, _G is a name like any other. Its only special status happens when Lua
creates the initial global table and assigns this table to the global variable _G. Lua does not care about the current value of this variable. But it is customary
to use this same name whenever we have a reference to the global environment,
as we did in the rewritten example.
我感觉这里说的_G的special status并没有什么special嘛。大家怎么看?
2015年09月21日 10点09分 1
level 11
它的特殊就是你声明全局变量的时候就会自动记录它,所以这就是特殊点,,,
2015年09月21日 12点09分 2
嗯,_G是有这个特点,但是上面那段话好像不是再说这个吧,我还是没看懂上面那段话。
2015年09月21日 13点09分
@chaosink 就是这个,下面是说lua不关心变量的值,而是关心它的名字
2015年09月21日 14点09分
level 11
难道我发言失败了,,,,_G特殊的地方就是会自动记录全局声明的东西。
2015年09月21日 12点09分 3
level 8
这里的特殊之处是指lua在创建虚拟机的时候会将最初的全局表保存到_G这个变量中,其余没什么区别。
二楼的说法是错的,声明全局变量的时候是保存到lua内部的一个表的,lua只是在启动的时候用_G来引用这个表,所以会造成全局变量是保存在_G的错觉。
2015年09月22日 02点09分 4
1