mirror of
https://github.com/luau-lang/luau.git
synced 2025-05-04 10:33:46 +01:00
Clarify and add example
This commit is contained in:
parent
1a60ffacf2
commit
4666fb6b98
1 changed files with 9 additions and 11 deletions
|
@ -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.
|
||||
|
|
Loading…
Add table
Reference in a new issue