_VERSION是Lua 5.1中剩下的唯一全局变量吗?
时间:2020-03-06 14:51:07 来源:igfitidea点击:
Lua 5.0文档对诸如_LOADED,LUA_PATH,_ALERT等(在Lua 5.1中无法使用)之类的东西感到困惑,我发现所有这些东西都已被删除,并将功能放在其他地方。我是否认为Lua 5.1中剩下的唯一一个全局变量是" _VERSION"?
解决方案
文档似乎认为几乎是这种情况。
_G A global variable (not a function) that holds the global environment (that is, _G._G = _G). Lua itself does not use this variable; changing its value does not affect any environment, nor vice-versa. (Use setfenv to change environments.)
看起来还有_PROMPT和_PROMPT2,但仅当以交互方式使用独立lua时:
If the global variable _PROMPT contains a string, then its value is used as the prompt. Similarly, if the global variable _PROMPT2 contains a string, its value is used as the secondary prompt (issued during incomplete statements). Therefore, both prompts can be changed directly on the command line or in any Lua programs by assigning to _PROMPT.
假设我们没有打开任何库,也有_G
,pairs,
ipairs和
newproxy`。