10 April, 2025
On March 5th, Second Life started the alpha test of their new scripting language SLua, which is heavily based on the Roblox Luau scripting language, which is itself a fork of Lua. That's a long way of saying that I've been writing a bunch of scripts in Lua recently! I've done a fair amount of LSL scripting and programming in various other languages in the past, but the last month of playing around with Lua has been some of the most concentrated focus on scripting that I've had in a long time. Mostly because it's so darn fun!
SLua meant to be an eventual replacement for the old LSL scripting language which has been in place in Second Life since its early beginnings, but the reality is that LSL will continue on into eternity as an option to write scripts in, with most LSL code being compiled on the back-end into SLua. It's an interesting scripting language because it's both more capable and more simplified than LSL. All of the functions of LSL are still present, nothing was left behind, things are only being added. SLua is more of a human-readable scripting language similar to Python: There are no semicolons, no curly brackets, much fewer parentheses, etc. Everything is meant to be easier to understand as common language, and a script written in SLua is generally shorter (fewer lines) than one written in LSL that does exactly the same thing.
One other major thing that SLua has going for it other than ease of use is efficiency. SLua scripts compile down to less than half the size of LSL scripts in most cases, and in some even less than that. This is important because scripts in Second Life are limited to 64KB in size, although there's been some talk that maybe that size limit could change someday... Fingers crossed! SLua is also significantly faster than LSL. SLua is still in kind of a debug mode during alpha testing so we're not really able to evaluate the full performance, but it's already faster than LSL and promises to only improve from here.
So, what are some examples of projects that I've written in SLua so far? Well, the first thing that I did on the very first day was try to write a simple sit-to-teleport script, just to see how easy it would be to rewrite an existing LSL script into SLua. And it wasn't so bad! I posted the results here as an early example.
My next major project was trying to write a simple game using SLua. I decided to make a simple jumping game where you try to avoid fireballs and catch coins, both of which are travelling towards you across a playfield. I wanted to make the game to get used to the concept of coroutines, which is a new feature in Lua that resembles (but isn't actually) parallel execution. You can pause a routine and come back to it later on in a cycle, basically. Through the use of ll.SetLinkPrimitiveParamsFast the game is able to animate 3+ different entities at the same time, while doing hit tracking and keeping track of the score, lives, etc. There's a picture and video of it here.
Next, I started to experiment with some HTTP requests using SLua, which honestly isn't all that different from how it works in LSL. I was kind of learning as I went in both languages. I made a tracker for the inworld user count in SL, and then I scripted a translator with enhanced functionality for communicating with SL Mobile residents using the Google Translate API. I actually wrote the translator in LSL first then converted it over to SLua manually. I was surprised with how simple the process of converting the script was, and how much shorter the script ended up being in the new language even though it had exactly the same functionality!
On the whole, I would say that SLua has been a great success as a project even though it's still in its alpha phase. The Lindens who have been working on it are highly motivated and provide a lot of good feedback to the testers, as well as frequent patches and server support. The people who've been testing it alongside me have been wonderful too, and generally understand a whole lot more about scripting and coding than I do! They've been a lot of help if I ever get stuck and I try my best to contribute whenever I can.
If you're interested in checking out the SLua alpha yourself, you can find a detailed writeup about it here on the wiki, and also the official news announcement regarding it here. I'd also recommend joining the official Second Life Discord Server and checking out the scripting and scripting-lua channels, it's a great place to ask questions and get answers.
See you on the beta grid!