docs: add hilbish.timers interface docs

docs-refactor
sammyette 2022-12-14 18:44:02 -04:00
parent 90023ffa89
commit 98eddf9004
Signed by: sammyette
GPG Key ID: 904FC49417B44DCD
6 changed files with 42 additions and 1 deletions

View File

@ -5,6 +5,7 @@ layout: apidoc
--- ---
## Introduction ## Introduction
Manage interactive jobs in Hilbish via Lua. Manage interactive jobs in Hilbish via Lua.
Jobs are the name of background tasks/commands. A job can be started via Jobs are the name of background tasks/commands. A job can be started via

View File

@ -9,7 +9,22 @@ The timers interface si one to easily set timeouts and intervals
to run functions after a certain time or repeatedly without using to run functions after a certain time or repeatedly without using
odd tricks. odd tricks.
## Object properties
- `type`: What type of timer it is
- `running`: If the timer is running
- `duration`: The duration in milliseconds that the timer will run
## Functions ## Functions
### start()
Starts a timer.
### stop() ### stop()
Stops a timer. Stops a timer.
### create(type, time, callback)
Creates a timer that runs based on the specified `time` in milliseconds.
The `type` can either be interval (value of 0) or timeout (value of 1).
### get(id)
Retrieves a timer via its ID.

View File

@ -155,6 +155,9 @@ function hilbish.jobs.stop() end
--- This is the equivalent of using `source`. --- This is the equivalent of using `source`.
function hilbish.runner.sh(cmd) end function hilbish.runner.sh(cmd) end
--- Starts a timer.
function hilbish.timers:start() end
--- Stops a timer. --- Stops a timer.
function hilbish.timers:stop() end function hilbish.timers:stop() end
@ -199,4 +202,11 @@ function hilbish.history.get(idx) end
--- @returns number --- @returns number
function hilbish.history.size() end function hilbish.history.size() end
--- Creates a timer that runs based on the specified `time` in milliseconds.
--- The `type` can either be interval (value of 0) or timeout (value of 1).
function hilbish.timers.create(type, time, callback) end
--- Retrieves a timer via its ID.
function hilbish.timers.get(id) end
return hilbish return hilbish

View File

@ -1,3 +1,4 @@
--- hilbish.runner
local currentRunner = 'hybrid' local currentRunner = 'hybrid'
local runners = {} local runners = {}

View File

@ -73,6 +73,10 @@ func (t *timer) stop() error {
return nil return nil
} }
// #interface timers
// #member
// start()
// Starts a timer.
func timerStart(thr *rt.Thread, c *rt.GoCont) (rt.Cont, error) { func timerStart(thr *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
if err := c.Check1Arg(); err != nil { if err := c.Check1Arg(); err != nil {
return nil, err return nil, err

View File

@ -61,6 +61,10 @@ func (th *timersModule) get(id int) *timer {
return th.timers[id] return th.timers[id]
} }
// #interface timers
// create(type, time, callback)
// Creates a timer that runs based on the specified `time` in milliseconds.
// The `type` can either be interval (value of 0) or timeout (value of 1).
func (th *timersModule) luaCreate(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { func (th *timersModule) luaCreate(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
if err := c.CheckNArgs(3); err != nil { if err := c.CheckNArgs(3); err != nil {
return nil, err return nil, err
@ -83,6 +87,9 @@ func (th *timersModule) luaCreate(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
return c.PushingNext1(t.Runtime, rt.UserDataValue(tmr.ud)), nil return c.PushingNext1(t.Runtime, rt.UserDataValue(tmr.ud)), nil
} }
// #interface timers
// get(id)
// Retrieves a timer via its ID.
func (th *timersModule) luaGet(thr *rt.Thread, c *rt.GoCont) (rt.Cont, error) { func (th *timersModule) luaGet(thr *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
if err := c.Check1Arg(); err != nil { if err := c.Check1Arg(); err != nil {
return nil, err return nil, err
@ -101,6 +108,9 @@ func (th *timersModule) luaGet(thr *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
} }
// #interface timers // #interface timers
// #property type What type of timer it is
// #property running If the timer is running
// #property duration The duration in milliseconds that the timer will run
// timeout and interval API // timeout and interval API
// The timers interface si one to easily set timeouts and intervals // The timers interface si one to easily set timeouts and intervals
// to run functions after a certain time or repeatedly without using // to run functions after a certain time or repeatedly without using