Standard Library

Overview

  • sric: Built-in standard library
  • cstd: C standard library wrappers
  • jsonc: JSON parsing/compression
  • serial: Serialization using dynamic reflection

API Documentation

Using C Libraries

The cstd module only exports common C functions - contributions welcome.

To use unexported C functions:

externc fun printf(format: raw* const Int8, args: ...);

fun main() {
    printf("Hello World\n");
}

Declare macros as const variables. See C++ Interop for details.

String

Strings are raw* const Int8 but auto-convert to String:

var str: String = "abc";

Explicit conversion when needed:

var str = asStr("abc");

DArray

Dynamic array (like C++ std::vector):

var a : DArray$<Int>;
a.add(1);
a.add(2);
verify(a[0] == 1);

HashMap

Key-value storage:

var map = HashMap$<Int, String>{};
map.set(1, "1");
map.set(2, "2");
verify(map[2] == "2");

File I/O

Using FileStream:

Write:

var stream = FileStream::open("tmp.txt", "wb");
stream.writeStr("Hello\nWorld");

Read:

var stream = FileStream::open("tmp.txt", "rb");
var line = stream.readAllStr();

Mode strings match C's fopen().