docs: document timer type, update generated docs

docs-types
sammyette 2023-01-07 12:57:34 -04:00
parent 503a322646
commit 1226801a78
Signed by: sammyette
GPG Key ID: 904FC49417B44DCD
4 changed files with 49 additions and 44 deletions

View File

@ -14,29 +14,7 @@ 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
interactive usage or with the functions defined below for use in external runners. interactive usage or with the functions defined below for use in external runners.
## Types
### Job
Job Type.
#### Properties
- `cmd`: The user entered command string for the job.
- `running`: Whether the job is running or not.
- `id`: The ID of the job in the job table
- `pid`: The Process ID
- `exitCode`: The last exit code of the job.
- `stdout`: The standard output of the job. This just means the normal logs of the process.
- `stderr`: The standard error stream of the process. This (usually) includes error messages of the job.
## Functions ## Functions
### background()
Puts a job in the background. This acts the same as initially running a job.
### foreground()
Puts a job in the foreground. This will cause it to run like it was
executed normally and wait for it to complete.
### start()
Starts running the job.
### stop() ### stop()
Stops the job from running. Stops the job from running.
@ -55,3 +33,26 @@ Get a job object via its ID.
### last() -> <a href="#job" style="text-decoration: none;">Job</a> ### last() -> <a href="#job" style="text-decoration: none;">Job</a>
Returns the last added job from the table. Returns the last added job from the table.
## Types
## Job
Job Type.
### Properties
- `cmd`: The user entered command string for the job.
- `running`: Whether the job is running or not.
- `id`: The ID of the job in the job table
- `pid`: The Process ID
- `exitCode`: The last exit code of the job.
- `stdout`: The standard output of the job. This just means the normal logs of the process.
- `stderr`: The standard error stream of the process. This (usually) includes error messages of the job.
### Methods
#### background()
Puts a job in the background. This acts the same as initially running a job.
#### foreground()
Puts a job in the foreground. This will cause it to run like it was
executed normally and wait for it to complete.
#### start()
Starts running the job.

View File

@ -22,35 +22,38 @@ All functions documented with the `Timer` type refer to a Timer object.
An example of usage: An example of usage:
``` ```
local t = hilbish.timers.create(1, 5000, function() local t = hilbish.timers.create(hilbish.timers.TIMEOUT, 5000, function()
print 'hello!' print 'hello!'
end) end)
t:stop()
print(t.running, t.duration, t.type)
t:start() t:start()
print(t.running) // true
``` ```
## Interface fields ## Interface fields
- `INTERVAL`: Constant for an interval timer type - `INTERVAL`: Constant for an interval timer type
- `TIMEOUT`: Constant for a timeout timer type - `TIMEOUT`: Constant for a timeout timer type
## Object properties ## Functions
### create(type, time, callback) -> <a href="#timer" style="text-decoration: none;">Timer</a>
Creates a timer that runs based on the specified `time` in milliseconds.
The `type` can either be `hilbish.timers.INTERVAL` or `hilbish.timers.TIMEOUT`
### get(id) -> <a href="#timer" style="text-decoration: none;">Timer</a>
Retrieves a timer via its ID.
## Types
## Timer
Timer type.
### Properties
- `type`: What type of timer it is - `type`: What type of timer it is
- `running`: If the timer is running - `running`: If the timer is running
- `duration`: The duration in milliseconds that the timer will run - `duration`: The duration in milliseconds that the timer will run
## Functions ### Methods
### start() #### start()
Starts a timer. 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 `hilbish.timers.INTERVAL` or `hilbish.timers.TIMEOUT`
### get(id) -> timer (Timer/Table)
Retrieves a timer via its ID.

View File

@ -15,6 +15,11 @@ const (
timerTimeout timerTimeout
) )
// #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
// Timer type.
type timer struct{ type timer struct{
id int id int
typ timerType typ timerType

View File

@ -62,7 +62,7 @@ func (th *timersModule) get(id int) *timer {
} }
// #interface timers // #interface timers
// create(type, time, callback) // create(type, time, callback) -> @Timer
// Creates a timer that runs based on the specified `time` in milliseconds. // Creates a timer that runs based on the specified `time` in milliseconds.
// The `type` can either be `hilbish.timers.INTERVAL` or `hilbish.timers.TIMEOUT` // The `type` can either be `hilbish.timers.INTERVAL` or `hilbish.timers.TIMEOUT`
// --- @param type number // --- @param type number
@ -91,7 +91,7 @@ func (th *timersModule) luaCreate(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
} }
// #interface timers // #interface timers
// get(id) -> timer (Timer/Table) // get(id) -> @Timer
// Retrieves a timer via its ID. // Retrieves a timer via its ID.
// --- @param id number // --- @param id number
// --- @returns Timer // --- @returns Timer
@ -115,9 +115,6 @@ func (th *timersModule) luaGet(thr *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
// #interface timers // #interface timers
// #field INTERVAL Constant for an interval timer type // #field INTERVAL Constant for an interval timer type
// #field TIMEOUT Constant for a timeout timer type // #field TIMEOUT Constant for a timeout timer type
// #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
/* /*
If you ever want to run a piece of code on a timed interval, or want to wait If you ever want to run a piece of code on a timed interval, or want to wait
@ -134,13 +131,12 @@ All functions documented with the `Timer` type refer to a Timer object.
An example of usage: An example of usage:
``` ```
local t = hilbish.timers.create(1, 5000, function() local t = hilbish.timers.create(hilbish.timers.TIMEOUT, 5000, function()
print 'hello!' print 'hello!'
end) end)
t:stop()
print(t.running, t.duration, t.type)
t:start() t:start()
print(t.running) // true
``` ```
*/ */
func (th *timersModule) loader(rtm *rt.Runtime) *rt.Table { func (th *timersModule) loader(rtm *rt.Runtime) *rt.Table {