Macro tealr::embed_compiler

source ·
embed_compiler!() { /* proc-macro */ }
Expand description

Embeds the teal compiler, making it easy to load teal files directly.

It can either download the given version from Github (default), luarocks or uses the compiler already installed on your system Compiling it without the lua5.3 compatibility library and embedding it into your application.

It returns a closure that takes the file that needs to run and returns valid lua code that both prepares the lua vm so it can run teal files and loads the given file using require, returning the result of the file that got loaded.

NOTE!

Due to how the teal files are being loaded, they won’t be typed checked. More info on: https://github.com/teal-language/tl/blob/master/docs/tutorial.md (Search for “loader”)

Compile time requirement!

A Teal compiler needs to be accessible in the path as tl. Running the teal compiler through command line (which this macro does) requires extra dependencies.

Example

Downloads:

 //This downloads from github
 let compiler = embed_compiler!("v0.9.0");

 let compiler = embed_compiler!(Github(version = "v0.9.0"));
 let compiler = embed_compiler!(Luarocks(version = "v0.9.0"));
 let lua_code = compiler("your_teal_file.tl");

From filesystem This example is not tested so it can show a nice path. There is however a test for it in /tests/

 let compiler = embed_compiler!(Local(path = "some/path/to/tl.tl"));
 //This tries to find the teal compiler on its own
 let compiler = embed_compiler!(Local());