Utilities
Helper functions for strings, tables, cryptography, and time.
String Functions
Extensions to the standard Lua string library.
-
string.split(str, sep) -> array
Split string by separator.
-
string.trim(str) -> string
Remove whitespace from both ends.
- string.starts_with(str, prefix) -> bool
- string.ends_with(str, suffix) -> bool
-
string.random(len) -> string
Generate random alphanumeric string.
Table Functions
Extensions to the standard Lua table library.
-
table.keys(tbl) -> array
Get all keys of a table.
-
table.values(tbl) -> array
Get all values of a table.
-
table.merge(t1, t2) -> table
Merge two tables (shallow copy). t2 overwrites t1.
-
table.map(tbl, fn) -> table
Apply function to each element.
-
table.filter(tbl, fn) -> table
Return new table with elements passing the predicate.
Crypto Functions
Cryptographic utilities via crypto global.
- crypto.md5(data) -> string
- crypto.sha256(data) -> string
- crypto.base64_encode(data) -> string
- crypto.base64_decode(data) -> string
- crypto.uuid() -> string (v4)
- crypto.jwt_encode(claims, secret) -> string
- crypto.jwt_decode(token, secret) -> table
-
crypto.hash_password(pwd) -> string
Argon2 hashing (Async).
- crypto.verify_password(hash, pwd) -> bool
Time Functions
Time utilities via time global.
- time.now() -> float (seconds)
- time.iso() -> string (ISO 8601)
-
time.sleep(ms) -> nil
Suspend execution for N ms (Non-blocking).
- time.format(ts, format) -> string
- time.parse(iso) -> float (seconds)
JSON Functions
JSON encoding and decoding via global json table.
-
json.encode(value) -> string
Convert Lua value (table, string, number, bool, nil) to JSON string.
-
json.decode(str) -> value
Parse JSON string to Lua value.
Example
-- Encode Lua table to JSON local data = { name = "Alice", age = 30, active = true } local json_str = json.encode(data) -- '{"name":"Alice","age":30,"active":true}' -- Decode JSON string to Lua table local parsed = json.decode('{"foo":"bar","nums":[1,2,3]}') print(parsed.foo) -- "bar" print(parsed.nums[2]) -- 2
Note: Also available as
solidb.json_encode() and solidb.json_decode().