Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

_ENV is not working in zerobrane studio on windows

When print(_ENV) is used in zerobrane studio on windows, it results into nil. Can we set _ENV variable to its expected use? 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.

like image 300
mathsbeauty Avatar asked Nov 21 '25 12:11

mathsbeauty


1 Answers

_ENV was introduced in Lua 5.2.

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

ZeroBrane runs the Lua 5.1 interpreter by default. You can pick another one via

main menu -> Project -> Lua Interpreter

In Lua 5.1 you could do something like this:

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.

like image 82
Piglet Avatar answered Nov 23 '25 05:11

Piglet



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!