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(): UUID
Returns the key (UUID) of the object's current owner.
GetOwner
()
const LLEvents: LLEvents
Event 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) => void
Registers 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: 128
Object 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(): UUID
Returns the key (UUID) of the object's current owner.
GetOwner
()
} }) const LLEvents: LLEvents
Event 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[]) => void
Registers 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(): UUID
Returns 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): void
Broadcasts 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(): string
Returns 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(): Vector
Returns 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