doc(lua): add main file for Lua API documentation

Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
Leonardo de Moura 2013-11-18 11:41:19 -08:00
parent 4d1d3d7cc7
commit 972721006e
2 changed files with 49 additions and 0 deletions

44
doc/lua/lua.md Normal file
View file

@ -0,0 +1,44 @@
# Lua API documentation
We the [Lua](http://www.lua.org) script language to customize and
extend [Lean](http://leanprover.net). This
[link](http://www.lua.org/docs.html) is a good starting point for
learning Lua. In this document, we focus on the Lean specific APIs.
Most of Lean components are exposed in the Lua API.
**Remark:** the script [md2lua.sh](md2lua.sh) extracts the Lua code
examples from the `*.md` documentation files in this directory.
## Hierarchical names
In Lean, we use _hierarchical names_ for identifying configuration
options, constants, and kernel objects. A hierarchical name is
essentially a list of strings and integers.
The following example demonstrates how to create and manipulate
hierarchical names using the Lua API.
```lua
local x = name("x") -- create a simple hierarchical name
local y = name("y")
-- In Lua, 'assert(p)' succeeds if 'p' does not evaluate to false (or nil)
assert(x == name("x")) -- test if 'x' is equal to 'name("x")'
assert(x ~= y) -- '~=' is the not equal operator in Lua
assert(x ~= "x")
assert(is_name(x)) -- test whether argument is a hierarchical name or not.
assert(not is_name("x"))
local x1 = name(x, 1) -- x1 is a name composed of the string "x" and number 1
assert(tostring(x1) == "x::1")
assert(x1 ~= name("x::1")) -- x1 is not equal to the string x::1
assert(x1 == name("x", 1))
local o = name("lean", "pp", "colors")
-- The previous construct is syntax sugar for the following expression
assert(o == name(name(name("lean"), "pp"), "colors"))
assert(x < y) -- '<' is a total order on hierarchical names
local h = x:hash() -- retrieve the hash code for 'x'
assert(h ~= y:hash())
```

5
doc/lua/md2lua.sh Executable file
View file

@ -0,0 +1,5 @@
#!/usr/bin/awk -f
BEGIN{ in_block = 0 }
!/```/{ if (in_block == 1) print $0; else print "" }
/```/{ in_block = 0; print "" }
/```lua/{ in_block = 1; print "" }