Write TypeScript
Run SLua
A TypeScript-to-Lua plugin for Second Life. Every LSL and SLua function is typed, so a bad call fails the build instead of the script.
$bunx @gwigz/slua-create
TypeScript in, Lua out
TSTL transpiles every example on this page
TypeScript
let let owner: UUIDowner = ll.function ll.GetOwner(): UUIDReturns the key (UUID) of the object's current owner.GetOwner()
const LLEvents: LLEventsEvent registration and management class for Second Life events. Supports adding multiple handlers per event and dynamic registration.
Event registration and management singleton for Second Life events.LLEvents.LLEvents.on<"changed">(event: "changed", callback: (changes: number) => void): (changes: number) => voidRegisters a handler function to run whenever the specified event occurs. Multiple handlers can be attached to the same event and will run in the order they were added. Returns the same function passed in so it can be used later with LLEvents:off().on("changed", (changed: numberchanged) => {
if ((changed: numberchanged & const CHANGED_OWNER: 128Object has changed owners. Triggers in the original object when a user takes it, copies it, or deeds it to a group, and in the new object when it is first rezzed.CHANGED_OWNER) !== 0) {
let owner: UUIDowner = ll.function ll.GetOwner(): UUIDReturns the key (UUID) of the object's current owner.GetOwner()
}
})
const LLEvents: LLEventsEvent registration and management class for Second Life events. Supports adding multiple handlers per event and dynamic registration.
Event registration and management singleton for Second Life events.LLEvents.LLEvents.on<"touch_start">(event: "touch_start", callback: (detected: DetectedEvent[]) => void): (detected: DetectedEvent[]) => voidRegisters a handler function to run whenever the specified event occurs. Multiple handlers can be attached to the same event and will run in the order they were added. Returns the same function passed in so it can be used later with LLEvents:off().on("touch_start", (events: DetectedEvent[]events) => {
for (const const event: DetectedEventevent of events: DetectedEvent[]events) {
if (const event: DetectedEventevent.DetectedEvent.getKey(): UUIDReturns the key (UUID) of the detected object or avatar specified by number, or NULL_KEY if number is not a valid index.getKey() === let owner: UUIDowner) {
ll.function ll.Say(channel: number, msg: string): voidBroadcasts the message msg to all scripts or agents listening on channel within llGetEnv("chat_range"), which is 20m on most regions. Agents listen on PUBLIC_CHANNEL (0) and DEBUG_CHANNEL (2147483647). All other channels are for script-to-script communication.Say(0, `${const event: DetectedEventevent.DetectedEvent.getName(): stringReturns a string representing the name of the detected object or avatar specified by item. Returns an empty string if item is not a valid index.getName()} touched at ${const event: DetectedEventevent.DetectedEvent.getTouchPos(): VectorReturns the vector position where the object was touched (specified by index) in region coordinates, or in screen-space coordinates if the object is attached as a HUD.getTouchPos()}`)
}
}
})SLua
local owner = ll.GetOwner()
LLEvents:on("changed", function(changed)
if bit32.btest(changed, CHANGED_OWNER) then
owner = ll.GetOwner()
end
end)
LLEvents:on("touch_start", function(events)
for ____, event in ipairs(events) do
if event:getKey() == owner then
ll.Say(0, (event:getName() .. " touched at ") .. tostring(event:getTouchPos()))
end
end
end)Transpiled with TypeScript-to-Lua
What you get
Type Definitions
Full LSL and SLua API coverage with autocomplete and inline docs.
TSTL Plugin
Bitwise ops, self-calls, index correction, and dead code elimination.
Modules
Coroutine-based async, config loading, and yield wrappers.
Playground
Try ts-slua in the browser with Monaco editor.
Scaffolding
Start a project with bunx @gwigz/slua-create.
Linting
oxlint config with SLua-specific rules.
Resources
Other places to find SLua tools and docs
Official
Function descriptions and API data sourced from lsl-definitions by Linden Lab and its contributors