documentation
Bun SDK
Connect to an l server from Bun with the @l-labs/bun IPC client.
The Bun SDK talks to a running l server over TCP through a small vendored C connector loaded with bun:ffi.
Install
Start an l server, then install dependencies in your Bun project:
l -p 5001
bun install
First query
import { LConnection, I, vF, vI, vS } from "@l-labs/bun";
const conn = LConnection.connect("localhost", 5001);
conn.execute("1+1"); // 2
conn.execute("sum", vI(1, 2, 3)); // 6
conn.execute("trade:([]sym:`A`B;price:1.5 2.5)");
conn.execute("select from trade where price>2"); // [{sym:"B", ...}]
conn.set("xs", vF(1.5, 2.5));
conn.close();
Calls are synchronous. Server errors throw Error, and the connection stays usable.
For exact wire types, use the generator functions:
| Shape | Generators |
|---|---|
| Atoms | B G H I J E F C S D T Z |
| Vectors | vG vH vI vJ vE vF vS vD vT vZ |
| Char vector | vC(string) |
Quickstart example
This example connects, queries, passes typed arguments, and sets a table from Bun-side vectors:
import { LConnection, I, vF, vI, vS } from "@l-labs/bun";
const port = parseInt(process.env.L_TEST_PORT || "5001");
const conn = LConnection.connect("localhost", port);
console.log(conn.execute("1+1")); // 2
console.log(conn.execute("til 10")); // [0, 1, ..., 9]
conn.execute("trade:([]sym:`IBM`MSFT`AAPL;price:120.5 340.2 175.8)");
console.log(conn.execute("select from trade where price > 200"));
// [{ sym: "MSFT", price: 340.2 }]
console.log(conn.execute("sum", vI(1, 2, 3, 4, 5))); // 15
console.log(conn.execute("{x+y}", I(10), I(32))); // 42
conn.set("t", {
sym: vS("IBM", "MSFT", "AAPL"),
price: vF(120.5, 340.2, 175.8),
qty: vI(100, 200, 300),
});
conn.execute("t: flip t");
console.table(conn.execute("select sym, price from t"));
conn.close();
Type mapping
| l type | Tag | JavaScript |
|---|---|---|
| boolean | 1 | boolean |
| byte, short, int, long | 4-7 | number |
| real, float | 8, 9 | number |
| char vector, symbol | 10, 11 | string |
| timestamp, timespan | 12, 16 | number raw i64 ns |
| month, minute, second, time | 13, 17-19 | number raw count |
| date, datetime | 14, 15 | Date |
| mixed list | 0 | any[] |
| table | 98 | array of row objects |
| dict | 99 | object or key/value pairs |
Plain JavaScript arguments convert the other way: numbers become int or float atoms, strings become symbols, arrays become vectors, objects become dicts, and booleans and dates map to their matching l values.