This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
Enviroment
Started by Sewbacca, 19 February 2016 - 09:26 PMPosted 19 February 2016 - 10:26 PM
Is it possible to start a function in a specific Environment?
Posted 19 February 2016 - 10:44 PM
Is it possible to start a function in a specific Environment?
I would suggest looking into setfenv.
http://www.gammon.co...php?lua=setfenv
Edited on 19 February 2016 - 09:44 PM
Posted 19 February 2016 - 10:56 PM
More specifically:
-- f <-- the function
-- env <-- the environement
setfenvReturnsToo = setfenv(f,env) -- but it also modifies the function it is given
Posted 19 February 2016 - 11:01 PM
THANKS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Posted 19 February 2016 - 11:48 PM
You're welcomeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Posted 20 February 2016 - 12:02 AM
For compatibility reasons, load should be used instead where possible.
Posted 20 February 2016 - 12:10 AM
To expand on what apemanzilla said, getfenv and setfenv are Lua 5.1 features, and will be removed from CC at some point, when the full update to Lua 5.2 is completed.
Posted 20 February 2016 - 01:59 PM
Do load the same thing like setfenv?
Posted 20 February 2016 - 02:15 PM
It combines loadstring and setfenv.
load(string,mode,env)
load(string,mode,env)
Posted 20 February 2016 - 06:42 PM
Posted 20 February 2016 - 09:42 PM
I'm not sure, that I get it right, setfenv will be remove in CC Lua 5.2.
Posted 20 February 2016 - 10:01 PM
Lua 5.2 has come out. As has 5.3. The thing is that CC uses Lua 5.1
Posted 21 February 2016 - 10:25 AM
Lua 5.2 has come out. As has 5.3. The thing is that CC uses Lua 5.1
I mean, will be setfenv removed, when CC uses Lua 5.2?
Edited on 21 February 2016 - 09:25 AM
Posted 21 February 2016 - 10:32 AM
Yes. There's no equivalent to setfenv in 5.2; it's not possible to code your own substitute.
http://lua-users.org/wiki/EnvironmentsTutorial
http://lua-users.org/wiki/EnvironmentsTutorial
Posted 21 February 2016 - 10:48 AM
Do you know, why setfenv will be removed? :(/>
Edited on 21 February 2016 - 09:49 AM
Posted 21 February 2016 - 10:58 AM
The answer here provides a pretty good example case as to when the new structure might serve better:
http://stackoverflow.com/questions/14290527/recreating-setfenv-in-lua-5-2
Whether or not that specific sort of thing was involved in the actual decision, I dunno.
http://stackoverflow.com/questions/14290527/recreating-setfenv-in-lua-5-2
Whether or not that specific sort of thing was involved in the actual decision, I dunno.