Skip to content

Latest commit

 

History

History
105 lines (80 loc) · 1.38 KB

README.md

File metadata and controls

105 lines (80 loc) · 1.38 KB

KCL WASM Library for Node.js and Browser

Quick Start

Node.js

npm install @kcl-lang/wasm-lib
import { load, invokeKCLRun } from "@kcl-lang/wasm-lib";

async function main() {
  const inst = await load();
  const result = invokeKCLRun(inst, {
    filename: "test.k",
    source: `
schema Person:
  name: str

p = Person {name = "Alice"}`,
  });
  console.log(result);
}

main();

Rust

cargo add kcl-wasm-lib --git https://github.com/kcl-lang/lib
cargo add anyhow
use anyhow::Result;
use kcl_wasm_lib::{KCLModule, RunOptions};

fn main() -> Result<()> {
    let opts = RunOptions {
        filename: "test.k".to_string(),
        source: "a = 1".to_string(),
    };
    let mut module = KCLModule::from_path("path/to/kcl.wasm")?;
    let result = module.run(&opts)?;
    println!("{}", result);
    Ok(())
}

Go

package main

import (
	"fmt"

	"github.com/kcl-lang/wasm-lib/pkg/module"
)

func main() {
	m, err := module.New("../../kcl.wasm")
	if err != nil {
		panic(err)
	}
	result, err := m.Run(&module.RunOptions{
		Filename: "test.k",
		Source:   "a = 1",
	})
	if err != nil {
		panic(err)
	}
	fmt.Println(result)
}

Developing

  • Install node.js
  • Install dependencies
npm install

Building

npm run compile

Testing

npm run test

Format

npm run format