initial
[lua-unibilium.git] / README
blobcfb485008b1c7eab0f7736169ec6afe414a66c48
1 This is lua-unibilium, lua bindings to unibilium.
3 Unibilium may be found at https://github.com/mauke/unibilium/
5 Assume you have
7         local unibi = require("unibilium")
9 in a lua script. Here is the translation to unibilium.h
11  - u = unibi.from_mem(mem)   -- unibi_from_mem
12    u = unibi.from_term(term) -- unibi_from_term
13    u = unibi.from_env()      -- unibi_from_env
15    These return (garbage-collected) unibi_term* objects. (unibi_from_fd
16    and unibi_from_fp are not directly wrapped -- use lua io mechanisms
17    and call unibi.from_mem for the same effect).
19  - z = u[X]
21    This pulls out a property from u, using one of the unibi_get_XYZ
22    family. X should be a string based on uninames.c in the unibilium
23    project. It can be a long-form property name, like "can_change", or a
24    short name, like "ccc". X may be an extended property, like "Tc".
26    If u does not have the property referred to by X, then z will be nil.
28    If X refers to a boolean property (like "ccc"), then z will be a
29    boolean. If X refers to a numeric property (like "cols"), then z will
30    be an integer. If X refers to a string property, like "sgr", then z
31    is an object wrapping that string (see below).
33    While unibilium allows setting (extended) properties, this binding
34    does not expose that feature.
37  - z(p1, p2, ...)
39    If z is is a (non-nil) string property from u, such as u["sgr"], then
40    z may be called. This invokes unibi_run, using the z itself as the
41    format parameter and p1, p2, ... as the arguments. The resulting
42    string is returned.
44    So the following should write "hello", then move the cursor to
45    (y=2,x=3), then write "world":
47         local unibi = require("unibilium")
48         u = unibi.from_env()
49         move = u["cursor_address"]
50         if move then
51                 io.write("hello" .. move(2, 3) .. "world")
52         end
54    If z takes more parameters than are provided, zeroes are silently
55    added. If z takes less parameters than are provided, the remainder
56    are silently discarded.