WL is a powerful and flexible, yet experimental scripting language for templating with first-class support for HTML.
To learn about the language check out the LANGUAGE.md file. But for a sneak peek, here's an example:
- Turing-complete language with first-class HTML support, procedures, and an import system
- Easy to embed: The interpreter is a single C file with no dependencies that performs no allocations or I/O
- Built-in XSS protection: escape() operator to sanitize dynamic HTML
The WL interpreter is intended to be used as a library, but you can use the CLI to get a feel for the language. You can compile it by running:
This will generate the wl executable that you can call to evaluate .wl files.
If you are using vscode, you can also install the language extension ide/vscode/wl-language by dropping it into your editor's extension folder and reloading it. The extension folder should be one of these:
- Windows: %USERPROFILE%\.vscode\extensions
- macOS: ~/.vscode/extensions
- Linux: ~/.vscode/extensions
If you're sold on the language and want to embed it in your application, just add the wl.c and wl.h files to your build and read the "Embedding" section.
If you get stuck, have questions, or want to contribute, feel free to open an issue or join my discord server here.
Happy templatin'!
WL programs need to first be translated to bytecode, then evaluated in a virtual machine. The bytecode is completely standalone and can be cached.
The API is quite involved as it tries not to take resource ownership from the caller. Ideally parent applications will have their own simplified wrapper over this API with caching and support for their own object model.
To compile a script, you need to create a WL_Compiler object and add the source file to it
If the initial script includes other files, the wl_compiler_add function will return an WL_AddResult of type WL_ADD_AGAIN and contain the path of the file that needs to be added next. The program will then need to call wl_compiler_add again with that file, until either an error occurs or WL_ADD_LINK is returned.
Once a bytecode program has been obtained, this is how you set up the virtual machine to run it:
When during the evaluation of a program the WL_EVAL_SYSVAR result is returned, it means the program referenced an external symbol as a variable. The host program needs to push onto the stack of the VM the value relative to that symbol.
Say your environment defined three external symbols "varA", "varB", "varC" with values 1, 2, 3. The way you would implement this is by doing:
You first check the name of the referenced symbol in res.str, then use one of the wl_push_* functions to add the associated value.
If the program performs a call to an external function, the VM will return a result of type WL_EVAL_SYSCALL.
The parent program can then get the number of arguments using the wl_arg_count function and wl_push_arg to set the top of the VM stack to the argument with the specified index. The argument can then be read using one of the wl_pop_* functions.
The caller then needs to push the return value of the call on top of the stack using one of the wl_push_* functions.
.png)

