Difference between revisions of "Setsafeenv"

From GiderosMobile
(Created page with "__NOTOC__ '''Available since:''' Gideros 2011.6<br/> '''Class:''' (global)<br/> === Description === Sets a safe environment to be used by the given function. <syntaxhighl...")
 
m
 
(One intermediate revision by the same user not shown)
Line 6: Line 6:
 
Sets a safe environment to be used by the given function.
 
Sets a safe environment to be used by the given function.
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
(varies) = setsafeenv(f,table)
+
(varies) = setsafeenv(flags)
 
</syntaxhighlight>
 
</syntaxhighlight>
  
''f'' 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.
+
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.
 +
 
 +
''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.
 
  As a special case, when f is 0 ''setsafeenv'' changes the environment of the running thread. In this case, ''setsafeenv'' returns no values.
  
 
=== Parameters ===
 
=== Parameters ===
'''f''': (varies) function or number(call stack level)<br/>
+
'''flags''': (varies) function or number(call stack level)<br/>
'''table''': (table) environment table to set<br/>
 
  
 
=== Return values ===
 
=== Return values ===
 
'''Returns''' (varies) returns provided function or nil<br/>
 
'''Returns''' (varies) returns provided function or nil<br/>
  
=== See also ===
+
=== Example ===
'''[[setfenv]]'''
+
<syntaxhighlight lang="lua">
 +
setsafeenv(-1)
 +
</syntaxhighlight>
 +
 
 +
=== Reference ===
 +
https://github.com/gideros/gideros/blob/master/winrt_xaml/giderosgame/giderosgame.Shared/lua.h#L209
  
 
{{(global)}}
 
{{(global)}}

Latest revision as of 09:52, 6 February 2025

Available since: Gideros 2011.6
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.

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