Standard library
legionhjyu ships with two kinds of built-in modules: ones implemented in Python (fast, always available) and ones implemented in .lhj itself (which you can read and learn from).
Built-in Python modules
These are available as soon as you install legionhjyu, with no extra steps.
| Module | Description |
|---|---|
math | Arithmetic functions, constants like pi and e |
strings | String manipulation: split, join, trim, replace, and more |
os | File I/O, environment variables, working directory, time |
Import them with summon:
lhj
summon math
summon strings
summon os
echo math.pi ## 3.141592653589793
echo strings.upper("hi") ## HI
echo os.getcwd() ## /home/user/projectsStandard library .lhj files
These live in ~/.legion/stdlib/ and are also importable by name.
| Module | Description |
|---|---|
io | File open/read/write/close |
collections | Stack, Queue, LinkedList, Counter |
random | Random numbers and sampling |
json_mod | JSON encode and decode |
lhj
summon random
summon collections
forge stack = collections.Stack()
stack.push(1)
stack.push(2)
echo stack.pop() ## 2Installed packages
The ~/.legion/packages/ directory holds packages installed with legion pkg install. They work the same way:
lhj
summon legion-colors as c
c.red("Something went wrong")
c.green("All good")See the package manager docs for how to install, remove, and publish packages.