|
Post by Bit on Apr 27, 2017 0:37:06 GMT
Hey y'all!
Just wanted to ask the following questions to all of you who know their fenv stuff.
A) Is there a way to set the current thread's env without using setfenv(num,env)?
B) What are some important uses of setting the current thread's env?
C) Would it be too impacting to remove the functionality of setfenv() being able to set the current thread's environment? (For your work, for example.)
I'm eager to hear your answers, as I'd like to see if disabling the ability of setting the current thread's env. would impact many of you. (For no particular reason, just pure curiosity)
|
|
chimmihc
New Member
Veteran
Posts: 8
ROBLOX Username: chimmihc
|
Post by chimmihc on Apr 27, 2017 13:00:40 GMT
fenv means function environment. setfenv / getfenv accept either a function or stack level.
|
|
|
Post by goulstem on Apr 27, 2017 16:13:23 GMT
A) Is there a way to set the current thread's env without using setfenv(num,env)? B) What are some important uses of setting the current thread's env? C) Would it be too impacting to remove the functionality of setfenv() being able to set the current thread's environment? (For your work, for example.) I've only really messed with function environments like twice.. don't know much about the topic. But here we g0. A) Can't you use rawset? :3 B) Uhhhhhhhh. Idk, I used it to pack a module's environment into the script's global environment when required. C) Removing the setfenv function would have no impact on my work.
|
|
|
Post by Bit on Apr 27, 2017 20:10:54 GMT
I doubt chimmihc got the question, but anyway, thanks both of you
|
|
|
Post by Bit on Apr 27, 2017 20:41:06 GMT
A) Also, rawset won't set the environment, but will add a value to a table under a certain index without invoking any of its metamethods. B) What if I told you that loading a module's content to the global environment no longer required to use getfenv? (Anyway this was about setfenv, not getfenv) C) Good to know
|
|
|
Post by cntkillme on Apr 27, 2017 21:14:42 GMT
"A) Is there a way to set the current thread's env without using setfenv(num,env)?" From Lua? No, assuming the debug library is out of the question as well.
"B) What are some important uses of setting the current thread's env?" No real use.
"C) Would it be too impacting to remove the functionality of setfenv() being able to set the current thread's environment? (For your work, for example.)" Not for any well written script.
Also you keep saying _thread_ and not _function_ which are different.
|
|
|
Post by Bit on Apr 27, 2017 21:15:34 GMT
Because I would only limit the ability of setfenv to be called with a number as the first argument in this hypothetical scenario (specifically 0* as that allows you to change the current thread's fenv), not affecting functions being passed to it, cntkillme And thanks for your feedback!
|
|
|
Post by cntkillme on Apr 27, 2017 21:17:00 GMT
Using a number as the first argument sets the environment of the function based on the stack level. The only time you affect the thread's env. is by passing 0.
|
|
|
Post by Bit on Apr 27, 2017 21:17:59 GMT
Oh, it was 0? I completely forgot about that, as 1 used outside of a function would return the thread's, thanks for that!
|
|