Clarify and add example

This commit is contained in:
Daniel P H Fox 2023-08-19 21:22:52 +01:00 committed by GitHub
parent 1a60ffacf2
commit 4666fb6b98
Signed by: DevComp
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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.