Jump to content




Enviroment

lua

  • You cannot reply to this topic
15 replies to this topic

#1 Sewbacca

  • Members
  • 450 posts
  • LocationStar Wars

Posted 19 February 2016 - 10:26 PM

Is it possible to start a function in a specific Environment?

#2 valithor

  • Members
  • 1,053 posts

Posted 19 February 2016 - 10:44 PM

View PostSewbacca, on 19 February 2016 - 10:26 PM, said:

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 by valithor, 19 February 2016 - 10:44 PM.


#3 Creator

    Mad Dash Victor

  • Members
  • 2,168 posts
  • LocationYou will never find me, muhahahahahaha

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


#4 Sewbacca

  • Members
  • 450 posts
  • LocationStar Wars

Posted 19 February 2016 - 11:01 PM

THANKS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

#5 Creator

    Mad Dash Victor

  • Members
  • 2,168 posts
  • LocationYou will never find me, muhahahahahaha

Posted 19 February 2016 - 11:48 PM

You're welcomeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

#6 apemanzilla

  • Members
  • 1,421 posts

Posted 20 February 2016 - 12:02 AM

For compatibility reasons, load should be used instead where possible.

#7 HPWebcamAble

  • Members
  • 933 posts
  • LocationWeb Development

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.

#8 Sewbacca

  • Members
  • 450 posts
  • LocationStar Wars

Posted 20 February 2016 - 01:59 PM

Do load the same thing like setfenv?

#9 Creator

    Mad Dash Victor

  • Members
  • 2,168 posts
  • LocationYou will never find me, muhahahahahaha

Posted 20 February 2016 - 02:15 PM

It combines loadstring and setfenv.

load(string,mode,env)

#10 HPWebcamAble

  • Members
  • 933 posts
  • LocationWeb Development

Posted 20 February 2016 - 06:42 PM

Read more about load() here:
http://www.lua.org/m...l.html#pdf-load

#11 Sewbacca

  • Members
  • 450 posts
  • LocationStar Wars

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.

#12 Creator

    Mad Dash Victor

  • Members
  • 2,168 posts
  • LocationYou will never find me, muhahahahahaha

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

#13 Sewbacca

  • Members
  • 450 posts
  • LocationStar Wars

Posted 21 February 2016 - 10:25 AM

View PostCreator, on 20 February 2016 - 10:01 PM, said:

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 by Sewbacca, 21 February 2016 - 10:25 AM.


#14 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

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...onmentsTutorial

#15 Sewbacca

  • Members
  • 450 posts
  • LocationStar Wars

Posted 21 February 2016 - 10:48 AM

Do you know, why setfenv will be removed? :(

Edited by Sewbacca, 21 February 2016 - 10:49 AM.


#16 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

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...fenv-in-lua-5-2

Whether or not that specific sort of thing was involved in the actual decision, I dunno.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users