0.1.4 • Published 1 year ago

@aliceoncesaidhallo/cart-luau v0.1.4

Weekly downloads
-
License
-
Repository
-
Last release
1 year ago

cart

To install dependencies:

bun install

Example usage

import type { Inode } from "@bjorn3/browser_wasi_shim";
import { File } from "@bjorn3/browser_wasi_shim";
import { Cart, CartOptions, Memory, stdIo } from "../../packages/cart";

const shared_mem = new Memory();

const fs = new Map<string, Inode>();

const cart = new Cart(
  new CartOptions({
    memory: shared_mem,
    args: [],
    env: [],
    fds: stdIo("", fs),
  })
);

async function run() {
  await cart.load(/*wasm path*/);
  const thread = cart.loadThreadFromString("fib", `
local function fib(n)
  if n == 0 then
    return 0
  elseif n == 1 then
    return 1
  else
    return fib(n - 1) + fib(n - 2)
  end
end

print(fib(10))
  `);
  if (!thread.valid) {
    throw new Error("Failed to load example");
  }
  await thread.execute();
}

run();
0.1.4

1 year ago