Skip to main content
The object module is the primary bridge between Lion programs and the JavaScript host environment. It covers everything from simple property access to calling methods deep in an object graph, constructing class instances, and serializing data to JSON strings.

Property access

object/get

Returns the value of a single key on an object.
["object/get", {"a": 1}, "a"]
Result: 1

object/get-path

Traverses a dot-separated path through nested objects and arrays. Numeric path segments index into arrays.
["object/get-path", {"a": {"b": {"c": 42}}}, "a.b.c"]
Result: 42 Array indexing with a numeric segment:
["object/get-path", {"users": [{"name": "Ada"}, {"name": "Turing"}]}, "users.1.name"]
Result: "Turing"
Dot-path segments are split on .. A numeric segment (digits only) indexes into an array at that position. A non-numeric segment accesses an object key. Accessing a missing key or an out-of-bounds index produces a typed error.

Inspection

object/keys

Returns an array of the string keys of an object.
["object/keys", {"a": 1, "b": 2}]
Result: ["a", "b"]

object/values

Returns an array of the values of an object.
["object/values", {"a": 1, "b": 2}]
Result: [1, 2]

Serialization

object/json-stringify

Serializes an object to a JSON string. Accepts the same arguments as JSON.stringify: the object, an optional replacer, and an optional indentation width.
["object/json-stringify", {"a": 1}, null, 2]
Result: "{\n \"a\": 1\n}"

Construction

object/new

Calls a JavaScript constructor with the provided arguments and returns the new instance. The first argument must resolve to a function (class) in the environment.
["object/new", "SomeClass", "arg1", "arg2"]
object/new is mainly useful when Lion programs interact with host objects injected through a custom environment, such as UI framework classes or Node.js built-ins.

Method access and invocation

object/get-method

Retrieves a method from an object and returns it bound to that object. Useful when you want to pass the method to a higher-order function.
["object/get-method", "obj", "methodName"]

object/call-method

Retrieves and immediately calls a method on an object, passing any additional arguments.
["object/call-method", "obj", "methodName", 1, 2]

object/get-method-path

Like object/get-method, but traverses a dot-separated path before retrieving the method. The method is bound to the object found at the parent path.
["object/get-method-path", "obj", "nested.methodName"]

object/call-method-path

Traverses a dot-separated path, then calls the method at the end of the path with the provided arguments.
["object/call-method-path", "obj", "nested.methodName", 1, 2]
In agent-style Lion programs it is common to alias call-method-path as "()" in the environment for a terser call syntax. See the host interop guide for a worked example.