Skip to content

Learn SLua

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:

  • Modern Language Features - coroutines, optional typing, objects, and more
  • Better Performance - Optimized runtime for complex operations
  • Familiar Syntax - If you know Lua, Python, or JavaScript, you’re already halfway there
  • Type Safety - Optional type annotations catch errors before runtime
  • Active Development - Regular improvements and new features

If you’re already familiar with LSL, SLua will feel familiar but more powerful. Here’s a quick comparison:

LSL
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
}
}
SLua
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 state
end

This 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 events
function LLEvents.touch_start(detected: {DetectedEvent})
-- Say hello in local chat
ll.Say(0, "Hello, Avatar!")
end

That’s it! Save this script in a prim and touch it to see it work.

Here’s the recommended path through the SLua documentation:

  1. Language Fundamentals - (HELP WANTED) Start here if you’re new to SLua or Lua
  2. From LSL to SLua - Converting your LSL knowledge to SLua
  3. Events and Handlers - (HELP WANTED) How to respond to world events
  4. Async Programming - (HELP WANTED) Writing asynchronous code with coroutines
  5. Working with Types - (HELP WANTED) Using SLua’s optional type system
  6. Standard Library - (HELP WANTED) Complete reference of available functions