# Compiler library

Just like Powerlang, almostLua also has a unique **compiler** library which can be used to interact with compile-time services. For example, you may want to insert a RetroStudio block that doesn't exist in almostLua, or optimize a heavy equation.

The compiler library contains the following functions: `InsertBlock`, `InsertBlockAndFunction`, `Equation`, `Path` , `credits`, `version`and `printexpbl`.&#x20;

***

The `InsertBlock` function inserts a specified RetroStudio block in such a way that it's not affected by previous blocks nor does it affect following blocks. `InsertBlockAndFunction` serves the same purpose, however it also calls a specified function after the block, which is helpful for setting up events or triggers that may not exist in almostLua.

The syntax of `InsertBlock`is as follows:

```lua
output1, output2, ... = compiler.InsertBlock(BlockName, ...)
```

where **BlockName** is the name of the block you'd like to insert, and ... are the arguments you'd like to pass. For example, if you wanted to insert a Print block, you'd do

```lua
compiler.InsertBlock("Print", "Hello world!")
```

You can find block names and parameters in a module called ProgrammingBlocksData located in the root folder of almostLua source code. Note that when calling InsertBlock, the block name must be a **string**, not a variable or any other data type. This is because this operation is done at the compiler level, and the compiler does not know the values of variables.

The `InsertBlockAndFunction` has similar functionality, except it tries to call a function you define with at most 5 outputs of the block created. The syntax is as follows:

```lua
compiler.InsertBlockAndFunction(BlockName, Function, ...)
```

Note that InsertBlockAndFunction does not return anything. Here's how you can redirect a Set Variable block to a function of your choosing:

<pre class="language-lua"><code class="lang-lua">compiler.InsertBlockAndFunction(
    "SetVariable1", 
<strong>    function(newValue) print(newValue) end, 
</strong>    "Hello from InsertBlockAndFunction!"
)
</code></pre>

***

The Equation and Path functions have similar syntax:

```lua
compiler.Equation(equation)
compiler.Path(path)

-- Example:
print(compiler.Equation("2 + 2 * 2")) -- 6
print(compiler.Path("game.Workspace.Baseplate")) -- Baseplate
```

The `credits`and `version`methods return static strings located in the root of the almostLua source code:

```lua
print(compiler.credits())
print(compiler.version())

-- almostLua has been created by vopwn55 and NicePotato, with special thanks to AyRay, Cristiano, Bri, and Ottofort.
-- Beta 0.9
```
