The compiler library is a library unique to Powerlang that allows you to interact with the compiler. Using this library you can inject raw code, and obtain the current version of Powerlang, as well as credits. You can check out all functions it offers by going to its documentation page: compiler
This library is handy when you need to use a block present in RetroStudio that hasn't been added to Powerlang yet, or when doing optimization.
Inserting Visual Scripting Blocks
The compiler library has two functions to insert raw Visual Scripting blocks: InsertBlock and InsertBlockConnectedLast. The former creates a block that runs as its own statement, whereas the latter is connected to the last block generated by the compiler. It is possible to use InsertBlockConnectedLast to create chains of Visual Scripting blocks. Below is a visual representation of both methods:
For separate statements, it is recommened to use InsertBlock instead of InsertBlockConnectedLast right after another line, as InsertBlockConnectedLast might be impacted by if/else statements or loops.
BlockName is the friendly name of the block, it must be unique. BlockID identifies the type of the block, e.g. the ID Addition corresponds to the Addition block. Block IDs can be found in ProgrammingBlocksData.lua in the Powerlang source.
Due to Powerlang limitations, an inserted block can only have one output.
Here's an example of inserting an Addition block to add 60 and 9:
Result = compiler.InsertBlock("Add", "Addition", 60, 9)
It is helpful for shared scripts to know what version of Powerlang they're running on.
The Powerlang version can be obtained using compiler.version(). It returns a string containing the version. So, doing print(compiler.version()) will output Beta 0.9 as of the time of writing this article.
The Powerlang credits can be obtained similarly using compiler.credits(). Doing print(compiler.credits()) will result in the following output:
Powerlang - The Ultimate Programming Language
(c) vopwn55, 2024
Special thanks to:
NicePotato - Being a good friend
RJAI - Emotional Support
Both the Version and Credits are StringValues located in the root of the Powerlang source code folder.