docs

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 5, 2026 License: MIT Imports: 4 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func Lookup

func Lookup(query string) (*Topic, *Entry, bool)

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

func LookupEntry(qualified string) (*Topic, *Entry, bool)

LookupEntry resolves "ns.member" (or "ns:member" for methods) to the entry and its owning topic.

func LookupMember

func LookupMember(ns, member string) (*Topic, *Entry, bool)

LookupMember resolves a namespace + member pair ("math", "floor").

func RenderAll

func RenderAll(o Options) string

RenderAll concatenates every topic page, separated by form feeds so the output pipes cleanly into a pager or a file.

func RenderEntry

func RenderEntry(t *Topic, e *Entry, o Options) string

RenderEntry renders a single member as a short page — the common case for `luascript doc math.floor`.

func RenderIndex

func RenderIndex(o Options) string

RenderIndex renders the table of contents shown by a bare `luascript doc`.

func RenderSearch

func RenderSearch(results []Result, o Options) string

RenderSearch renders apropos results, one per line.

func RenderTopic

func RenderTopic(t *Topic, o Options) string

RenderTopic renders one topic as a man page.

func Suggest

func Suggest(query string) []string

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

type Result struct {
	Topic *Topic
	// Entry is nil when the topic itself matched.
	Entry *Entry
}

Result is one hit from Search.

func Search(q string) []Result

Search is apropos: a case-insensitive substring match over topic names, titles, member names, signatures, and summaries. Results are ordered topics-first, then by qualified name.

func (Result) Name

func (r Result) Name() string

Name renders the result's fully qualified name.

func (Result) Summary

func (r Result) Summary() string

Summary renders the result's one-line description.

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 All

func All() []Topic

All returns every topic, sorted by name.

func LookupTopic

func LookupTopic(name string) (*Topic, bool)

LookupTopic resolves a topic by name or alias.

func Topics

func Topics(k Kind) []Topic

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.

func (*Topic) Constants

func (t *Topic) Constants() []Entry

Constants returns the topic's non-callable entries.

func (*Topic) Functions

func (t *Topic) Functions() []Entry

Functions returns the topic's callable entries, Keywords its syntactic ones, and Constants the rest. All three preserve declaration order, which the data files keep meaningful (constructors first, then operations).

func (*Topic) Keywords

func (t *Topic) Keywords() []Entry

Keywords returns the topic's syntactic constructs.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL