Skip to content

Coroutine yield helper module #15

@gwigz

Description

@gwigz

Should be able to use SLua coroutines to flatten callback APIs into sequential code, including the following.

Runtime

  • spawn(fn) run a function inside a coroutine so it can yield
  • waitFor(event, filter?) yield until an LLEvents event fires (with optional predicate)
  • sleep(seconds) yield for N seconds via LLTimers.once

Dataserver Wrappers

  • requestAgentData(id, type) yields, returns string
  • requestDisplayName(id) yields, returns string
  • requestSimulatorData(region, type) yields, returns string
  • requestInventoryData(item) yields, returns string
  • readNotecardLine(name, line) yields, returns string
  • readNotecard(name) yields, returns string[] (loops until EOF)
  • findNotecardTextCount(name, pattern, opts) yields, returns string

Key-Value Store Wrappers (dataserver-based)

  • kvRead(key) -> { ok: boolean, value: string }
  • kvCreate(key, value) -> boolean
  • kvUpdate(key, value) -> boolean
  • kvDelete(key) -> boolean
  • kvSize() -> { used: number, total: number }

Dialog & TextBox

  • dialog(avatarId, text, buttons) yields, returns button text (manages listen channel internally)
  • textBox(avatarId, text) yields, returns typed text

HTTP

  • httpRequest(url, params, body) yields, returns { status, metadata, body }

Permissions

  • requestPermissions(avatarId, mask) yields, returns granted flags
  • transferMoney(avatarId, amount) yields, returns { success, message }

Sensor

  • sensor(name, id, type, range, arc) yields, returns DetectedEvent[] | null

Note, I'm not sure but there's probably also plans for official callback style APIs at some point, but this may still be good as a stand in.

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions