Skip to the content.

Designing a host standard library

ReScripted does not ship a huge stdlib. The host is the stdlib. You invent the surface and bind it.

Steps

  1. Write the function names in the language JSON:
    • builtins.functions: ["print", "len", "abs", "spawn"]
    • custom.host_functions: same or extra
    • standard_library.available: true if you are providing a set
    • standard_library.modules: names of packages (["math", "fs"])
    • standard_library.automatically_imported: those names are imported at the start of every run (after you add_library them)
  2. Shipping stdlib: compile stdlib/math.c++ with the app (target_sources). In C++ call engine.add_library("math", rescripted::library::math). Do not have CMake register names. See libraries.md.
  3. Runtime packages: add_library / add_library_file / load_plugin after startup.
  4. Put example calls in examples on the JSON (hello_world, function, …).
  5. Tell the user in a short comment in their main.cpp what each bind does.

Naming

Defaults you may replace

Name Default behavior
print Join args with spaces, return that string (no stdout)
len Length of array, string, or map; else 0
str to_string of first arg
type "null", "bool", "number", "string", "array", "map", "function"

Unsafe binds

Do not bind filesystem, eval-of-C++, or network unless the user asked. Scripts are arbitrary text loaded at runtime. See SECURITY.md in the ReScripted repo.

Standard library as scripts

engine.add_library_file("prelude", "stdlib/prelude.mylang") makes import prelude load that file at runtime. Embed the same file and add_library("prelude", source, language) to ship it in the binary. Document both layers in the user’s repo.