This repo mainly includes the binding of the low-level API and spec of the KCL language core, and the SDKs of various languages are based on this to encapsulate higher-level APIs.
cargo add --git https://github.com/kcl-lang/lib
Write the Code
use kcl_lang::*;
use anyhow::Result;
fn main() -> Result<()> {
let api = API::default();
let args = &ExecProgramArgs {
k_filename_list: vec!["main.k".to_string()],
k_code_list: vec!["a = 1".to_string()],
..Default::default()
};
let exec_result = api.exec_program(args)?;
println!("{}", exec_result.yaml_result);
Ok(())
}
go get kcl-lang.io/lib
Write the Code
package main
import (
"kcl-lang.io/lib"
)
func main() {
path = "path/to/install/lib"
_ := lib.InstallKclvm(path)
}
See here for more information.
python3 -m pip install kcl_lib
Write the code
import kcl_lib.api as api
args = api.ExecProgram_Args(k_filename_list=["./tests/test_data/schema.k"])
api = api.API()
result = api.exec_program(args)
print(result.yaml_result)
import { execProgram, ExecProgramArgs } from 'kcl-lib'
function main() {
const result = execProgram(ExecProgramArgs(['__test__/test_data/schema.k']))
console.log(result.yamlResult)
}
main();