gpt4 book ai didi

lua - _ENV 在 Windows 上的 Zerobrane Studio 中不工作

转载 作者:行者123 更新时间:2023-12-05 03:30:38 25 4
gpt4 key购买 nike

print(_ENV) 在 windows 上的 zerobrane studio 中使用时,结果为 nil。我们可以将 _ENV 变量设置为预期用途吗?作为代码示例,

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)

此代码在 windows 上的 zerobrane studio 中抛出错误。

最佳答案

_ENV 是在 Lua 5.2 中引入的。

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

ZeroBrane 默认运行 Lua 5.1 解释器。您可以通过以下方式选择另一个

主菜单 -> 项目 -> Lua 解释器

在 Lua 5.1 中你可以这样做:

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

我还没有花太多心思在这上面。所以可能不是 100% 等效。

关于lua - _ENV 在 Windows 上的 Zerobrane Studio 中不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70784233/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com