tbl
Object-as-map table helpers - type-checked get with optional default, set a string key, presence check, list keys, list values, and shallow copy. A thin, safe wrapper over ofld/oset/okeys with explicit error messages.
Load with: use tbl
What this module does
tbl treats ilusm objects as string-keyed tables. Every function
checks that its first argument is an object and throws a clear error if not.
Keys are always coerced to strings. This makes tbl a safer
alternative to bare ofld/oset calls when working
with dynamic key access patterns.
Quick example
use tbl
t = {name: "Alice", score: 42}
prn(tblge(t, "name", "anon")) # "Alice"
prn(tblge(t, "age", 0)) # 0 (default)
t = tblse(t, "level", 5)
prn(tblha(t, "level")) # tru
prn(tblky(t)) # ["name", "score", "level"]
prn(tblvl(t)) # ["Alice", 42, 5]
copy = tblcp(t) # shallow copy
Functions
Table operations
tblge(t, key, default)Gets the value for key in table t. Returns default[0] if the key is absent, or nil if no default is provided. Errors if t is not an object.
tblse(t, key, val)Returns a new table with key set to val. Key is coerced to a string.
tblha(t, key)Returns tru if key is present in t.
tblky(t)Returns the list of all keys in t.
tblvl(t)Returns the list of all values in t in the same order as tblky.
tblcp(t)Returns a shallow copy of t - a new object with all key-value pairs copied.
Notes
- Requires
trl.