Transpiler
Transpile a LSL script to SLua
This tool converts your LSL scripts into SLua. Paste your LSL script into the script box and click on “Transpile”.
- it needs scripts that compile without error in LSL (it doesn’t check syntax)
- it works with LSL scripts only, without preprocessor commands
- it doesn’t work with states or jump
Its intention is to provide a script that can be compiled and executed in SLua, but it still will need improvements, especially about structuring the data into SLua tables.
- It’s a work in progress, you can report issues and suggestions below.
- There are more details at the end of the page What it does and what it does not.
The scripts are processed internally and not stored or shared. I will only see the script if you click on “Report issue”.
On the resulting SLua script, hover your mouse on its top right and click “copy” to copy the script to your clipboard.
Report issues
If the transpiler didn’t work correctly, you can report the issue below. There are two common cases:
- Transpiler error: You receive an error message and no SLua script is returned.
- Script issue: You receive a SLua script, but it doesn’t work properly when tested in Second Life.
Make sure your LSL script is still in the box above, it will be sent as a file attachment to help understand the issue. You can also add a comment describing what is wrong.
Your Second Life username is optional, but feel free to include it if you’d like a follow-up.
Thank you for helping improve the SLua transpiler!
What it does and what it does not
What it does:
- changes syntax, keywords and operators
- defines all variables as local and initializes them with their default value (if they weren’t in LSL)
- typecasts between number and boolean and between string and uuid
- tries to identify which LSL integer variables are used as boolean
- replaces TRUE/FALSE with true/false or 1/0
- generates a numeric loop for when the pattern is clear enough, otherwise, it generates a loop while
- replaces assignation to vector/rotation components with a new vector/rotation
- replaces assignations in expressions with inline functions
- replaces llGetListLength with the # length operator
- replaces multiline strings with [[ ]] strings.
- adds a line (before the first function) declaring the functions that are defined after they are used
- renames variables that are SLua keywords (by adding _t at the end)
- renames state_entry() in the default state to initialize() and calls it at the end
What it does not (but will do, if possible, when we have the definitive version of SLua events)
- states
- events in states other than default are renamed adding the state name and _ at the start
- the command state name_of_state; is replaced with state = “name_of_state”
What it does not (but could do, if I receive requests for it)
- add type annotations for type-checking and linting, useful when we have the Luau analyzer in SLua
- change LL math functions to the math library
- change LL string functions to the string library, but they don’t work with Unicode
- change LL list functions to the table library when possible
- loop for
- check for more cases that can be converted to a numeric for
- in a numeric loop for:
- check that the variables used in the for are not modified inside the loop
- check that the index variable is not used after the loop
- remove the declaration of the index variable
- use integers with bit32 functions to get signed numbers when they are in arithmetic operations
- change “jump” to “break” or “continue” when possible
- change “else if” to “elseif” when possible
- preserve the formatting of lists declarations, when they are written in several lines or tabbed
What it does not (and probably will not, since these are very uncommon situations)
- side effects in the right operand of “and” and “or”
- LSL always evaluates the right operand, SLua only when necessary
- side effects in assignations and functions in an expression
- LSL evaluates variables and functions from right to left, SLua from left to right
What it does not (and will not, since it would require redesigning the code)
- jump (except when it can be replaced with break or continue)
- the command
jump name_of_label;
is replaced withjump = "jump name_of_label"
- the label
@name_of_label;
is replaced withjump = "@name_of_label"
- the command