Quirrel4.41.0

debug.doc

Defined in module "debug"
from "debug" import doc

Returns a documentation string for a function, class, or instance

examples/debug/doc-basic.nut
from "debug" import doc

function greet() {
  @@"Prints a friendly greeting."
  println("hi")
}

println("doc(greet) =", doc(greet))
Output:
doc(greet) = Prints a friendly greeting.

Parameters

subjectfunction|instance|classthe function, class, or instance to look up

Return value

The docstring attached to subject, or null when it has none.

An instance has no docstring of its own; passing one returns its class's docstring instead.

Errors

subject must already be a function, instance, or class; passing anything else fails the parameter type check before this function runs.

Notes

Script code attaches a docstring with @@"..." as the first thing inside a function or class body. Table docstrings are not supported:

function greet() {
  @@"Prints a friendly greeting."
  println("hi")
}

A native function only has a docstring when its binding registered one; most methods on the built-in types (array, string, ...) do not, so doc on them is null.

Example

examples/debug/doc.nut
from "debug" import doc

class Greeter {
  @@"Says hello politely."
  constructor() {}
}

println("doc(Greeter) =", doc(Greeter))
println("doc(Greeter()) =", doc(Greeter()))  // an instance looks up its class's docstring
println("doc([].insert) =", doc([].insert))  // no docstring was registered for this native
Output:
doc(Greeter) = Says hello politely.
doc(Greeter()) = Says hello politely.
doc([].insert) = null

See also

get_function_info_tableReturns meta information about a function as table
get_function_decl_stringReturns a function declaration string
debugmodule index