debug.doc
Returns a documentation string for a function, class, or instance
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
subject | function|instance|class | the 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
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 nativeOutput:
doc(Greeter) = Says hello politely.
doc(Greeter()) = Says hello politely.
doc([].insert) = nullSee also
get_function_info_table | Returns meta information about a function as table |
get_function_decl_string | Returns a function declaration string |
| debug | module index |