Back to Knowledge Base
Lua Playground: Getting Started
What is the Lua Playground?
Section titled “What is the Lua Playground?”The Lua Playground is an interactive editor for testing Lua scripts against the live CoCoCo environment. Use it to develop Scripts and Custom Actions before deploying them.
How to open it
Section titled “How to open it”Go to Menu → Developer → Lua Playground.
Example script
Section titled “Example script”-- Query recent jobslocal res = ctx.graphql.query([[ query { listJobs(first: 5) { edges { node { id name status } } } }]])
for _, edge in ipairs(res.data.listJobs.edges) do ctx.log.info(edge.node.name, { status = edge.node.status })endClick Run to execute. Output appears in the console below.
Available APIs (tenant Scripts)
Section titled “Available APIs (tenant Scripts)”| API | What it does |
|---|---|
ctx.graphql.query(gql, vars) | Run a GraphQL query or mutation |
ctx.sql.query(sql) | Read from the reporting tables |
ctx.cache.get(key) / ctx.cache.set({key, value, ttl?}) / ctx.cache.delete(key) | Tenant cache (Redis) |
ctx.device.http(idOrAlias, opts) / ctx.device.sql(idOrAlias, opts) | Talk to a device via its Bridge |
ctx.config.get(key) | Read one Tenant Config value by key (Secret values redacted) |
ctx.template.render(handle, contextJSON) | Render a saved JDF/JMF template by handle |
ctx.time.now() / ctx.time.nowIso() | Timestamps (os.* is sandboxed away) |
ctx.json.encode/decode(...) | JSON |
ctx.log.info/warn/error(msg, attrs?) | Write to the console (print is disabled) |
Tenant Scripts run with the base API only — ctx.dataContainer is custom-app-only. There
is no generic outbound-HTTP API (only device-scoped ctx.device.http).