Jump to content




setFenv,getFenv, loadString help


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

#1 HurricaneCoder

  • Members
  • 52 posts

Posted 27 June 2013 - 03:22 PM

I want to know what does setFenv, getFenv, loadString does. I have read the lua wiki but it does not help me one bit.

#2 H4X0RZ

  • Members
  • 1,315 posts
  • LocationGermany

Posted 27 June 2013 - 04:06 PM

setfenv:
Spoiler


#3 HurricaneCoder

  • Members
  • 52 posts

Posted 27 June 2013 - 04:15 PM

View PostFreack100, on 27 June 2013 - 04:06 PM, said:

setfenv:
Spoiler

Thx that helps me a lot but can you explain to me what is getFenv as well?

#4 GopherAtl

  • Members
  • 888 posts

Posted 27 June 2013 - 04:30 PM

getfenv gets a function's environment. I'd've thought that was obvious from the explanation of setfenv...

#5 H4X0RZ

  • Members
  • 1,315 posts
  • LocationGermany

Posted 27 June 2013 - 04:32 PM

Yea, I'm not sure if my explaination of getfenv is right but here is it:
Spoiler
EDIT:
Damn ninjas :D


#6 GopherAtl

  • Members
  • 888 posts

Posted 27 June 2013 - 04:38 PM

:ninja:

To explain a bit more, getfenv() with no arguments gets the current function environment, i.e., what your current function or program is running in. getfenv(myfunc) returns the function environment of the specified function. And getfenv(#), where # is an integer, can be used to get the function environment of parent scopes. The applications of the last are a bit obscure, most frequently you'll want either getfenv() to get the current environment, or getfenv(myfunc) to get the environment of a specific function.

#7 Imgoodisher

  • Members
  • 67 posts
  • LocationYes

Posted 27 June 2013 - 04:45 PM

loadstring takes a string and tries to load it as lua code. If it works with no errors, it returns a function that does the code you gave it, otherwise it returns nil and an error message
For example,
func = loadstring("print('Hello World!')")
func()
will print 'Hello World!'

loadstring("print('Hello World!'")
would return nil and "lua: 1: [string "string"]: 1: ')' expected" because it's missing the ending )





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users