little is a small, fast, easily embeddable language implemented in C.
var speak = fn(animal) {
if animal is "cat" { return "meow" }
elseif animal is "dog" { return "woof" }
elseif animal is "mouse" { return "squeak" }
return "???"
}
var animals = [ "cat", "dog", "mouse", "monkey" ]
for animal in array.each(animals) {
io.print(string.format("%s says %s!", animal, speak(animal)))
}- Tiny implementation - core langauge is <2500 sloc in a single .h/.c pair
- Light embedding - compiles down to less than 20kb, 3 API calls to get started
- Reasonably fast for realtime applications
- Low memory footprint with simple mark and sweep garbage collector
- Supports null, numbers, booleans, strings, functions, closures, arrays, tables, and native procedures
- Optional, consise stdlib - an extra ~1000 sloc
- Supports 32- and 64-bit, and will likely compile anywhere!
- Feature-rich C api to integrate and interact with the VM
#include "little.h"
#include "little_std.h"
#include "little_async.h"
// this is called if the vm encounters an error, letting us react
void my_error_callback(lt_VM* vm, const char* msg)
{
printf("LT ERROR: %s\n", msg);
}
int main(char** argv, int argc)
{
lt_VM* vm = lt_open(malloc, free, my_error_callback); // open new VM
ltstd_open_all(vm); // register stdlib
ltasync_open_all(vm); // optional Promise, timer, and task libs
const char* my_source_code = ... // read source from file/stream/string
uint16_t n_return = lt_dostring(vm, my_source_code, "my_module") // run code as "my_module"
if(n_return) printf("LT RETURNED: %s", ltstd_tostring(vm, lt_pop(vm))); // if our code returns, print the result
}The included Taskfile is the supported development workflow:
task build
build/little.exe --help
build/little.exe scripts/hello.little
build/little.exe -e 'io.print("hello")'
build/little.exe -I lib scripts/main.littleThe CLI accepts one script path, or -e SOURCE for a short inline program. It
returns a non-zero exit code for command-line, file, parse, or runtime errors.
Use --help to see its options and --version to see the linked API version.
Use -I DIRECTORY (more than once if needed) to add source-module search paths
without baking those local launch details into the script.
For a local Windows compiler, copy .env.example to .env and set GCC_PATH
to the w64devkit root; the Taskfile loads that file without committing it.
GitHub Actions builds and tests on Windows and Linux. It downloads the
pinned WebUI submodule and compiles WebUI without launching a GUI. Pull requests
targeting develop produce per-PR development packages. Pushes to develop
produce development packages after merges; pushes to main produce optimized
release packages after merges from develop. The workflow can also be manually
run for any ref, defaulting to develop, with either package type.
Each run uploads one self-contained package for every target:
little-windows-x64.zipcontainslittle.exe,libs/json/json.dll, andlibs/webui/webui.dll.little-linux-x64.zipcontainslittle,libs/json/json.so, andlibs/webui/webui.so.
gcc -std=c11 main.c src/little_buffer.c src/little.c src/little_common.c src/little_std.c src/little_loadlib.c src/little_std_io.c src/little_std_math.c src/little_std_array.c src/little_std_table.c src/little_std_string.c src/little_std_gc.c src/little_async.c -lm -pthread -rdynamic -ldl -o little
you need msys2 just follow the installation instructions
pacman -S mingw-w64-ucrt-x86_64-gcc
gcc main.c src/little_buffer.c src/little.c src/little_common.c src/little_std.c src/little_loadlib.c src/little_std_io.c src/little_std_math.c src/little_std_array.c src/little_std_table.c src/little_std_string.c src/little_std_gc.c src/little_async.c -Wl,--export-all-symbols -o little- Language overview
- Syntax rules
- Runtime and compiler limits
- Standard library
- Task API
- C API reference
- C API examples
- Runnable scripts
Feel free to open an issue or pull request if you feel you have something meaninfgul to add, but keep in mind the language is minimalist by design, so any merging will be very carefully picked
Please see LICENSE for details