Use function "import" to gain access to Lua built-in objects & functions
This commit is contained in:
parent
bbd498ab39
commit
df8dd3d9ac
16
doc/doc.md
16
doc/doc.md
|
@ -311,7 +311,7 @@ They can be documented just like 'public' functions:
|
|||
--- we need to give a hint here for foo
|
||||
-- @local here
|
||||
function foo(...) .. end
|
||||
|
||||
|
||||
### Alternative way of specifying tags
|
||||
|
||||
Since 1.3, LDoc allows the use of _colons_ instead of @.
|
||||
|
@ -1254,6 +1254,7 @@ The string this function returns will be what's actually gets written out.
|
|||
|
||||
_Available functions are:_
|
||||
|
||||
- `import(obj)` exposes Lua object `obj` to config.ld
|
||||
- `alias(a,tag)` provide an alias `a` for the tag `tag`, for instance `p` as short for
|
||||
`param`
|
||||
- `add_language_extension(ext,lang)` here `lang` may be either 'c' or 'lua', and `ext` is
|
||||
|
@ -1267,6 +1268,19 @@ that means `@tparam Object`.
|
|||
extracted values will be passed to `handler`. It is expected to return link text
|
||||
and a suitable URI. (This match will happen before default processing.)
|
||||
|
||||
## Importing Lua Objects
|
||||
|
||||
The `import` function is available to gain access to built-in Lua functions & objects.
|
||||
|
||||
```
|
||||
local print = import("print")
|
||||
local string = import("string")
|
||||
|
||||
for _, s in ipairs({string.split("Hello world!")}) do
|
||||
print(s)
|
||||
end
|
||||
```
|
||||
|
||||
## Annotations and Searching for Tags
|
||||
|
||||
Annotations are special tags that can be used to keep track of internal development status.
|
||||
|
|
6
ldoc.lua
6
ldoc.lua
|
@ -240,6 +240,10 @@ function ldoc.custom_see_handler(pat, handler)
|
|||
doc.add_custom_see_handler(pat, handler)
|
||||
end
|
||||
|
||||
function ldoc.import(t)
|
||||
return (_G[t])
|
||||
end
|
||||
|
||||
local ldoc_contents = {
|
||||
'alias','add_language_extension','custom_tags','new_type','add_section', 'tparam_alias',
|
||||
'file','project','title','package', 'icon','format','output','dir','ext', 'topics',
|
||||
|
@ -252,7 +256,7 @@ local ldoc_contents = {
|
|||
'dont_escape_underscore','global_lookup','prettify_files','convert_opt', 'user_keywords',
|
||||
'postprocess_html',
|
||||
'custom_css','version',
|
||||
'no_args_infer'
|
||||
'no_args_infer', 'import'
|
||||
}
|
||||
ldoc_contents = tablex.makeset(ldoc_contents)
|
||||
|
||||
|
|
Loading…
Reference in New Issue