Language Basics
Variables, types, functions, and control flow
SLua brings modern scripting to Second Life using Luau, a high-performance typed variant of Lua developed by Roblox. If you’re familiar with Lua, Python, JavaScript, or other modern languages, you’ll feel right at home.
SLua offers several advantages for Second Life scripting:
If you’re already familiar with LSL, SLua will feel familiar but more powerful. Here’s a quick comparison:
integer gIsRed = TRUE;
default { touch_start(integer total_number) { llSay(0, "Changing color!");
if (gIsRed) { llSetColor(<0.0, 1.0, 0.0>, ALL_SIDES); } else { llSetColor(<1.0, 0.0, 0.0>, ALL_SIDES); }
gIsRed = !gIsRed; // Toggle state }}local isRed: boolean = true
function LLEvents.touch_start(detected: {DetectedEvent}) ll.Say(0, "Changing color!")
if isRed then ll.SetColor(vector(0.0, 1.0, 0.0), ALL_SIDES) else ll.SetColor(vector(1.0, 0.0, 0.0), ALL_SIDES) end
isRed = not isRed -- Toggle stateendThis guide will take you from SLua basics to advanced scripting:
Language Basics
Variables, types, functions, and control flow
Working with Events
Handle touch, collision, timer, and other events
Async Operations
Use coroutines for cleaner asynchronous code
Type System
Leverage optional types for safer code
Standard Library
Work with strings, tables, math, and more
Migration Guide
Convert your LSL scripts to SLua
Let’s write your first SLua script. This simple script makes an object say “Hello!” when touched:
-- Listen for touch eventsfunction LLEvents.touch_start(detected: {DetectedEvent}) -- Say hello in local chat ll.Say(0, "Hello, Avatar!")endThat’s it! Save this script in a prim and touch it to see it work.
Here’s the recommended path through the SLua documentation: