Users › 09 Std and packaging
Print anything, use the String API, and ship compiled modules.
Core Lopolith has no I/O. Everything you have printed so far came from
Std, a native singleton in lib/Std.so:
#import Std
Std.print("x = ", x, ", y = ", y, "\n")
print is variadic: any number of arguments, any types. Each
argument is formatted by its static type:
| Argument type | Output |
|---|---|
bool | true / false |
| integer types | decimal |
float / double | shortest round-trip form; nan, inf, -inf |
String | contents; null prints null |
| other references | the class name |
| arrays | [a, b, c], nested arrays included |
Floating-point printing is the shortest representation that round-trips, and
integral values never use scientific notation: 100.0 prints
100, while 1.0e30 prints 1e+30.
| Method | Behavior |
|---|---|
int length() | byte length |
int indexOf(String sub) | first index or -1 |
String substring(int start, int end) | clamped to the string bounds |
String toString() | the string itself |
bool ___equals(String) | content equality, used by == |
Remember: arrays use the field a.length, strings use the method
s.length().
loth compile writes portable bytecode for the file and its
whole dependency closure:
$ loth compile com/example/todo/Main.loth -o build
wrote build/com/example/todo/Main.lothc (812 bytes)
wrote build/com/example/todo/Task.lothc (491 bytes)
... (Std, Runnable, Thread, ...)
$ loth run -e com.example.todo.Main -cp build build/com/example/todo/Main.lothc
Hello from the task list
com.example.todo.Main
becomes build/com/example/todo/Main.lothc.-e picks the entry class and -cp
tells the loader where the sibling .lothc and .so
files live.lib/ (the directory beside the loth binary)..lothc from untrusted
sources the way you would treat untrusted bytecode anywhere else.The task-list example uses exactly this flow.
%simple com.example.std.Demo implements Main
#import Std
int run(int argc, String[] argv) Main@run {
Std.print("int=", 42, " long=", 42L, " d=", 100.0, " f=", 0.1f,
" b=", true, " null=", null, "\n")
int[] a = {1, 2, 3}
Std.print("arr=", a, "\n")
String s = "hello world"
Std.print("len=", s.length(), " idx=", s.indexOf("world"),
" sub=", s.substring(0, 5), "\n")
return 0
}
int=42 long=42 d=100 f=0.1 b=true null=null
arr=[1, 2, 3]
len=11 idx=6 sub=hello