KCL WASM Library for Node.js and Browser
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 ( ) ;
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 ( ( ) )
}
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 )
}
Install node.js
Install dependencies