mirror of
https://github.com/luau-lang/luau.git
synced 2025-05-04 10:33:46 +01:00
Update read-only-environment.md
This commit is contained in:
parent
b8eb56ecb6
commit
97dbcf5926
1 changed files with 11 additions and 7 deletions
|
@ -12,16 +12,20 @@ getfenv and setfenv there are outlined cases where reading the environment is us
|
||||||
Increased performance can be achieved for transpilers written in Luau that may not be able to have a static environment created to access functions from or cant directly transpile 1:1. Similarly
|
Increased performance can be achieved for transpilers written in Luau that may not be able to have a static environment created to access functions from or cant directly transpile 1:1. Similarly
|
||||||
interpreters written in Luau can benefit from being able to access functions without deoptimization, making other optimizations still active.
|
interpreters written in Luau can benefit from being able to access functions without deoptimization, making other optimizations still active.
|
||||||
|
|
||||||
...
|
|
||||||
|
|
||||||
## Design
|
## Design
|
||||||
|
|
||||||
...
|
A safe way to access the environment is with a read-only table with `__index` and `__iter` metamethods.
|
||||||
|
|
||||||
|
a) `_ENV` table
|
||||||
|
|
||||||
|
A read-only global table with metamethods that point to `LUA_ENVIRONINDEX`.
|
||||||
|
|
||||||
|
b) `getenv` or `getrenv` function
|
||||||
|
|
||||||
|
Works identically to `getfenv` but only provides read-only access to the function's environment.
|
||||||
|
|
||||||
## Drawbacks
|
## Drawbacks
|
||||||
|
|
||||||
...
|
Type-checking can be difficult.
|
||||||
|
|
||||||
## Alternatives
|
Roblox's marketplace currently hides assets that use `getfenv` so it would need to be updated to hide assets with `_ENV`/`getenv`/`getrenv`.
|
||||||
|
|
||||||
...
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue