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.

ModuleDescription
mathArithmetic functions, constants like pi and e
stringsString manipulation: split, join, trim, replace, and more
osFile 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/projects

Standard library .lhj files

These live in ~/.legion/stdlib/ and are also importable by name.

ModuleDescription
ioFile open/read/write/close
collectionsStack, Queue, LinkedList, Counter
randomRandom numbers and sampling
json_modJSON encode and decode
lhj
summon random
summon collections

forge stack = collections.Stack()
stack.push(1)
stack.push(2)
echo stack.pop()    ## 2

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