Difference between revisions of "Setsafeenv"
From GiderosMobile
m |
|||
Line 1: | Line 1: | ||
__NOTOC__ | __NOTOC__ | ||
− | '''Available since:''' Gideros | + | '''Available since:''' Gideros 2025.2<br/> |
'''Class:''' [[(global)]]<br/> | '''Class:''' [[(global)]]<br/> | ||
Line 10: | Line 10: | ||
Gideros 2025.2 introduces a new global function ''setsafeenv(flags)'' which tells Luau the global environment is "safe" and so enables optimizations. ''flags'' parameter indicates which optimizations to enable, and you'll probably want them all by using -1 value. | Gideros 2025.2 introduces a new global function ''setsafeenv(flags)'' which tells Luau the global environment is "safe" and so enables optimizations. ''flags'' parameter indicates which optimizations to enable, and you'll probably want them all by using -1 value. | ||
+ | |||
+ | '''To enable optimizations, ''setsafeenv'' assumes that you don’t redefine global functions (math, pairs, ipairs, ...), even your own!''' | ||
''flags'' can be a Lua function or a number that specifies the function at that stack level: Level 1 is the function calling ''setsafeenv''. ''setsafeenv'' returns the given function. | ''flags'' can be a Lua function or a number that specifies the function at that stack level: Level 1 is the function calling ''setsafeenv''. ''setsafeenv'' returns the given function. |
Latest revision as of 01:26, 19 May 2025
Available since: Gideros 2025.2
Class: (global)
Description
Sets a safe environment to be used by the given function.
(varies) = setsafeenv(flags)
Gideros 2025.2 introduces a new global function setsafeenv(flags) which tells Luau the global environment is "safe" and so enables optimizations. flags parameter indicates which optimizations to enable, and you'll probably want them all by using -1 value.
To enable optimizations, setsafeenv assumes that you don’t redefine global functions (math, pairs, ipairs, ...), even your own!
flags can be a Lua function or a number that specifies the function at that stack level: Level 1 is the function calling setsafeenv. setsafeenv returns the given function.
As a special case, when f is 0 setsafeenv changes the environment of the running thread. In this case, setsafeenv returns no values.
Parameters
flags: (varies) function or number(call stack level)
Return values
Returns (varies) returns provided function or nil
Example
setsafeenv(-1)
Reference
https://github.com/gideros/gideros/blob/master/winrt_xaml/giderosgame/giderosgame.Shared/lua.h#L209