Modules & Packages
Tekst has source modules, package directories, and native standard-library modules. Native modules are provided by the runtime and do not require .tk source files.
Import modules
The preferred module syntax is use module. Existing import statements remain supported for compatibility.
use math
use random
print(math.sqrt(144))
print(random.randint(1, 6))Import selected names
Use from module use name to import a specific name directly.
from math use sqrt
from random use randint
print(sqrt(81))
print(randint(1, 6))Local modules
Local .tk files can be loaded with use module or from module use name. The older import spelling remains available. The native compiler expands imported source into the compilation unit.
main.tk
helpers.tk
lib/
text.tk
packages/
mathpkg/
dec.tk
square.tkPackages
Package directories can contain multiple .tk files. A dec.tk file is loaded first when present. Project packages are resolved from the project packages/ directory.
use mathpkgFor the project layout above, this loads the package at packages/mathpkg/.
Native modules
The compiler recognizes these built-in modules: math, random, fs, time, os, json, socket, smtp, and http.
Native backend status
The native backend supports module imports. Source-level try/catch is not currently lowered by the native compiler.
