972721006e
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
1.6 KiB
1.6 KiB
Lua API documentation
We the Lua script language to customize and extend Lean. This link 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 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.
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())