From 4666fb6b98edaa7ffe2d265a81422047f53fc5d4 Mon Sep 17 00:00:00 2001 From: Daniel P H Fox Date: Sat, 19 Aug 2023 21:22:52 +0100 Subject: [PATCH] Clarify and add example --- rfcs/syntax-static-imports.md | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/rfcs/syntax-static-imports.md b/rfcs/syntax-static-imports.md index f3f5bcae..6ade1b1d 100644 --- a/rfcs/syntax-static-imports.md +++ b/rfcs/syntax-static-imports.md @@ -228,17 +228,7 @@ local Tween, Spring = Fusion.Tween, Fusion.Spring import * from Package.Libraries.Fusion ``` -Individual functions, `do` blocks or other scopes can statically import into their namespace without spilling imports to other code and without introducing extra scopes or indentation. The imports are resolved ahead of time, so they need not even call into C code more than once: - -```Lua -do - local fast_eq = require(Package.Libraries.fast_eq) - function AbstractLayer:fast_eq(other) - return fast_eq(self._ir, other._ir) - end -end --- fast_eq is not accessible here -``` +Individual functions, `do` blocks or other scopes can statically import into their namespace without spilling imports to other code, just as they can do today. ```Lua function AbstractLayer:fast_eq(other) @@ -248,6 +238,14 @@ end -- fast_eq is not accessible here ``` +Dynamic code can continue to use `require()`, just as they do today. + +```Lua +for _, child in script:GetChildren() do + require(child)() +end +``` + ## Drawbacks `require()` keeps in line with existing Lua 5.1 codebases, and already serves the basic function of importing modules. It may be nice to keep the consistency between static and dynamic imports, even at the expense of some of the features listed here. It's easier to understand where values are imported to when expressed in a familiar `local x = y` construct, though admittedly this does not quite extend to type importing.