From 7ac31cfd8ca5442eb3650e3c03626a34d67e4234 Mon Sep 17 00:00:00 2001 From: Gael <85808999+TheGreatSageEqualToHeaven@users.noreply.github.com> Date: Mon, 14 Aug 2023 15:48:33 +0100 Subject: [PATCH] Update read-only-environment.md --- rfcs/read-only-environment.md | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/rfcs/read-only-environment.md b/rfcs/read-only-environment.md index 21488768..300b9a4c 100644 --- a/rfcs/read-only-environment.md +++ b/rfcs/read-only-environment.md @@ -2,32 +2,19 @@ ## Summary -Add a way to access a read-only version of the environment without disabling `safeenv`. +Add `_ENV` as a safe alternative to `getfenv`. ## Motivation There are valid use cases for accessing the environment in a read-only way. As defined in the [RFC](https://github.com/Roblox/luau/blob/master/rfcs/deprecate-getfenv-setfenv.md) for deprecating getfenv and setfenv there are outlined cases where reading the environment is useful. -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. +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. ## 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. +A read-only global table `_ENV` with clones of all base functions and libraries. ## Drawbacks -Type-checking can be difficult. - -Roblox's marketplace currently hides assets that use `getfenv` so it would need to be updated to hide assets with `_ENV`/`getenv`/`getrenv`. - -Environments can have metamethods of their own which may not interface well with a read-only `getenv`/`getrenv`. +Roblox's marketplace currently hides assets that use `getfenv` so it would need to be updated to hide assets with `_ENV`.