I want to know what does setFenv, getFenv, loadString does. I have read the lua wiki but it does not help me one bit.
setFenv,getFenv, loadString help
Started by HurricaneCoder, Jun 27 2013 03:22 PM
6 replies to this topic
#1
Posted 27 June 2013 - 03:22 PM
#2
Posted 27 June 2013 - 04:06 PM
setfenv:
Spoiler
#4
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
Posted 27 June 2013 - 04:32 PM
Yea, I'm not sure if my explaination of getfenv is right but here is it:
Damn ninjas
Spoiler
EDIT:Damn ninjas
#6
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.
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
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,
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












