简体   繁体   English

_ENV 在 windows 上的 zerobrane 工作室中不工作

[英]_ENV is not working in zerobrane studio on windows

When print(_ENV) is used in zerobrane studio on windows, it results into nil.当在 windows 上的 zerobrane studio 中使用print(_ENV)时,结果为 nil。 Can we set _ENV variable to its expected use?我们可以将 _ENV 变量设置为预期用途吗? As an example of code,作为代码示例,

a = 15                      -- create a global variable
      _ENV = {g = _G}             -- change current environment
      a = 1                       -- create a field in _ENV
      g.print(_ENV.a, g.a)

This code throws the error in zerobrane studio on windows.此代码在 windows 上的 zerobrane studio 中引发错误。

_ENV was introduced in Lua 5.2. _ENV在 Lua 5.2 中引入。

See https://www.lua.org/manual/5.2/manual.html#8.1https://www.lua.org/manual/5.2/manual.html#8.1

ZeroBrane runs the Lua 5.1 interpreter by default. ZeroBrane 默认运行 Lua 5.1 解释器。 You can pick another one via您可以通过以下方式选择另一个

main menu -> Project -> Lua Interpreter主菜单 -> 项目 -> Lua 解释器

In Lua 5.1 you could do something like this:在 Lua 5.1 中,您可以执行以下操作:

a = 15
setfenv(1, {g = _G})
_ENV = g.getfenv()
a = 1
g.print(_ENV.a, g.a)

I haven't spent too much thought on it.我没有花太多心思在这上面。 So probably it is not 100% equivalent.所以可能它不是100%等效的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM