-
Notifications
You must be signed in to change notification settings - Fork 0
Require
cyxigo edited this page Jul 13, 2026
·
1 revision
Keeping all the code in one file is not a good idea. Programming projects tend to be organized into multiple files. Wi has that ability too - using the require statement.
Let's imagine there are 2 files: a.wi and b.wi.
// b.wi
var x = 10;// a.wiWe want that x variable to be used from a.wi. So, we require a b.wi file!
// a.wi
require "b.wi" = b;
print(b.x); // 10So when we write require "b.wi" = b;, we tell Wi to:
- Load file
b.wiand execute it. - Store its global variables into a new global object named
b.
require can only be used in top-level code.
It's also worth mentioning that freshly created object b is just like any other variable.
Wi checks for file existence at compile time:
// a.wi
require "c.wi" = c;This results in a compile error:
compile error: file c.wi does not exist
|
1 | require "c.wi" = c;
| ^^^^^^
--> a.wi:1:9