Documentation
¶
Overview ¶
Package docs is the single source of truth for luascript's reference documentation: one curated entry per built-in global, library function, native module member, and object method.
It is deliberately data-only (no VM, no compiler imports) so every consumer can share it:
- `luascript doc` renders topics as man pages (cmd/luascript/doc.go)
- the REPL's `doc <topic>` command prints the same pages
- the LSP server derives completion + hover from it (internal/lsp/server)
The data is hand-maintained; it is NOT reflected out of the VM, because summaries and signatures cannot be recovered from a *vm.GoFunc. What the runtime *can* check is drift — cmd/luascript's TestDocsMatchRuntime loads every native module and fails when a documented member no longer exists, and `luascript doc -audit` reports members that exist but are undocumented.
Index ¶
- func Lookup(query string) (*Topic, *Entry, bool)
- func LookupEntry(qualified string) (*Topic, *Entry, bool)
- func LookupMember(ns, member string) (*Topic, *Entry, bool)
- func RenderAll(o Options) string
- func RenderEntry(t *Topic, e *Entry, o Options) string
- func RenderIndex(o Options) string
- func RenderSearch(results []Result, o Options) string
- func RenderTopic(t *Topic, o Options) string
- func Suggest(query string) []string
- func TopicNames() []string
- type Entry
- type EntryKind
- type Kind
- type Options
- type Result
- type Topic
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Lookup ¶
Lookup resolves a free-form query the way the CLI wants it: a topic name wins over a member of the same spelling, then "ns.member" / "ns:member". It reports the topic, the entry (nil when the whole topic matched), and whether anything was found.
func LookupEntry ¶
LookupEntry resolves "ns.member" (or "ns:member" for methods) to the entry and its owning topic.
func LookupMember ¶
LookupMember resolves a namespace + member pair ("math", "floor").
func RenderAll ¶
RenderAll concatenates every topic page, separated by form feeds so the output pipes cleanly into a pager or a file.
func RenderEntry ¶
RenderEntry renders a single member as a short page — the common case for `luascript doc math.floor`.
func RenderIndex ¶
RenderIndex renders the table of contents shown by a bare `luascript doc`.
func RenderSearch ¶
RenderSearch renders apropos results, one per line.
func RenderTopic ¶
RenderTopic renders one topic as a man page.
func Suggest ¶
Suggest returns names close to a failed query: prefix matches first, then substring matches, then — when neither found anything — names within a small edit distance, which is what catches an actual typo. Capped at 8 so the error stays readable.
func TopicNames ¶
func TopicNames() []string
TopicNames returns every lookup key, sorted — used for shell completion and the "did you mean" suggestion on a miss.
Types ¶
type Entry ¶
type Entry struct {
// Name is the bare member name as it appears at runtime ("floor").
// It must match the key the VM actually installs — the drift test
// compares these against a live module table.
Name string
// Signature is the qualified call form ("math.floor(x): number").
Signature string
// Summary is a single sentence, shown in indexes and search results.
Summary string
// Detail is optional extra prose shown only on the full page.
Detail string
Kind EntryKind
}
Entry is one documented name inside a topic.
type EntryKind ¶
type EntryKind string
EntryKind separates callables from data so the renderer can group them under FUNCTIONS / METHODS and CONSTANTS / FIELDS.
const ( EntryFunction EntryKind = "function" EntryMethod EntryKind = "method" EntryConstant EntryKind = "constant" EntryField EntryKind = "field" // EntryKeyword is a syntactic construct rather than a value — it has // no runtime member to check against, so the drift audit skips it. EntryKeyword EntryKind = "keyword" )
type Kind ¶
type Kind string
Kind classifies a topic, which drives both the index grouping and the man-page header ("MODULE" vs "OBJECT" and so on).
const ( // KindCore is the base library: globals installed into _G with no // namespace of their own (print, pcall, setmetatable, ...). KindCore Kind = "core" // KindLibrary is an auto-global namespace — available without a // require (string, table, math, coroutine, io). KindLibrary Kind = "library" // KindModule is a native module reached through require(). KindModule Kind = "module" // KindObject is a value returned by a constructor, documented for its // methods (a file handle, a compiled regex, a figure, ...). KindObject Kind = "object" )
type Options ¶
type Options struct {
// Width is the target line width for wrapped prose.
Width int
// Color enables ANSI bold on headings and signatures.
Color bool
}
Options controls rendering. The zero value is valid: 80 columns, no color.
type Result ¶
Result is one hit from Search.
type Topic ¶
type Topic struct {
// Name is the lookup key and the page title ("math", "std.stack").
Name string
Kind Kind
// Aliases are alternative lookup keys ("globals" for "_G").
Aliases []string
// Title is the short "name — title" line under NAME.
Title string
// Synopsis is how you get hold of the namespace, verbatim luascript.
Synopsis string
// Detail is the DESCRIPTION body. Blank lines separate paragraphs;
// lines starting with two spaces are kept verbatim (code samples).
Detail string
Entries []Entry
// Example is a runnable snippet, printed verbatim under EXAMPLES.
Example string
// SeeAlso lists related topic names.
SeeAlso []string
// RuntimeModule is the require() name whose live table backs this
// topic, when there is one. Only set for KindModule and for objects
// reachable from a module; the drift audit uses it.
RuntimeModule string
// RuntimeGlobal is the auto-global namespace backing this topic —
// "string", "math", ... or "_G" for the globals table itself. A topic
// may set both this and RuntimeModule (math and io do), in which case
// the audit checks the union of the two surfaces.
RuntimeGlobal string
// Requireable marks an auto-global namespace that ALSO has a native
// module of the same name with a larger surface (math and io). Such a
// topic documents the union and is listed under both index headings;
// entries that exist on only one of the two say so in their Detail.
Requireable bool
}
Topic is one man page: a namespace and everything reachable through it.
func LookupTopic ¶
LookupTopic resolves a topic by name or alias.
func Topics ¶
Topics returns the topics of one kind, sorted by name. A Requireable library (math, io) is reported under KindModule as well, since that is where someone hunting for a require target will look for it.