Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions .github/workflows/lua-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,28 @@ permissions:

jobs:
build-and-test:
strategy:
matrix:
lua_version: ["5.1", "5.2", "5.3", "5.4", "luajit-2.1"]
defaults:
run:
working-directory: "lua"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Setup lua toolchain
run: |
sudo apt-get update
sudo apt-get install -y lua-busted luarocks liblua5.2-dev
uses: leafo/gh-actions-lua@v13
with:
luaVersion: "${{ matrix.lua_version }}"
- name: Setup luarocks
uses: leafo/gh-actions-luarocks@v6
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: 1.91
override: true
components: clippy, rustfmt
- name: Build
run: make
run: luarocks make ./*.rockspec
- name: Test
run: luarocks test ./*.rockspec
6 changes: 5 additions & 1 deletion lua/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ edition = "2024"
publish = false

[features]
default = ["mlua/lua52"]
lua51 = ["mlua", "mlua/lua51"]
lua52 = ["mlua", "mlua/lua52"]
lua53 = ["mlua", "mlua/lua53"]
lua54 = ["mlua", "mlua/lua54"]
luajit = ["mlua", "mlua/luajit"]
luajit52 = ["mlua", "mlua/luajit52"]

[lib]
crate-type = ["cdylib"]
Expand Down
45 changes: 26 additions & 19 deletions lua/kcl_lib-0.12.3-1.rockspec
Original file line number Diff line number Diff line change
@@ -1,28 +1,35 @@
package = "kcl_lib"
version = "0.12.3-1"
local package_version = "0.12.3"
local rockspec_revision = "1"

rockspec_format = "3.0"
package = "kcl_lib"
version = package_version .. "-" .. rockspec_revision
source = {
url = "git+https://github.com/kcl-lang/kcl",
url = "git+https://github.com/kcl-lang/lib",
-- tag = "lua/v" .. version,
}

description = {
summary = "KCL Lua Bindings",
detailed = [[
KCL Lua Bindings
summary = "KCL Lua Bindings",
detailed = [[
KCL Lua Bindings
]],
homepage = "https://kcl-lang.io/",
license = " Apache-2.0"
homepage = "https://kcl-lang.io/",
license = " Apache-2.0",
}

dependencies = {
"lua >= 5.1",
"luarocks-build-rust-mlua = 0.2.0",
"lua >= 5.1",
"luarocks-build-rust-mlua = 0.2.0",
}
test_dependencies = {
"busted >= 2.2",
}
test = {
type = "busted",
}

build = {
type = "rust-mlua",
modules = {
["kcl_lib"] = "kcl_lib_lua",
},
target_path = "target",
}
type = "rust-mlua",
modules = {
["kcl_lib"] = "kcl_lib_lua",
},
target_path = "target",
}
4 changes: 3 additions & 1 deletion lua/test/exec_test.lua → lua/spec/exec_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ local kcl_lib = require("kcl_lib")
describe("kcl lua lib unit test", function()
describe("exec_program", function()
it("operator function in fs schema", function()
local result, err = kcl_lib.exec_program({k_filename_list=["./test_data/schema.k"]})
local result, err = kcl_lib.exec_program({
k_filename_list = { "./spec/test_data/schema.k" },
})
assert.is_nil(err)
assert.are.equal(result.yaml_result, "app:\n replicas: 2")
end)
Expand Down
File renamed without changes.
8 changes: 4 additions & 4 deletions lua/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ use mlua::prelude::*;
/// Execute KCL file with arguments and return the JSON/YAML result.
fn exec_program<'a>(lua: &'a Lua, args: LuaTable<'a>) -> LuaResult<LuaTable<'a>> {
let api = kcl_api::API::default();
let work_dir: String = args.get("work_dir")?;
let k_filename_list: Vec<String> = args.get("k_filename_list")?;
let k_code_list: Vec<String> = args.get("k_code_list")?;
let work_dir: String = args.get("work_dir").unwrap_or_default();
let k_filename_list: Vec<String> = args.get("k_filename_list").unwrap_or_default();
let k_code_list: Vec<String> = args.get("k_code_list").unwrap_or_default();

let result = match api.exec_program(&kcl_api::ExecProgramArgs {
work_dir,
Expand All @@ -28,7 +28,7 @@ fn exec_program<'a>(lua: &'a Lua, args: LuaTable<'a>) -> LuaResult<LuaTable<'a>>
}

#[mlua::lua_module]
fn kcl_lib(lua: &Lua) -> LuaResult<LuaTable> {
fn kcl_lib(lua: &Lua) -> LuaResult<LuaTable<'_>> {
let module = lua.create_table()?;
module.set("exec_program", lua.create_function(exec_program)?)?;
Ok(module)
Expand Down
10 changes: 10 additions & 0 deletions lua/stylua.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
column_width = 80
line_endings = "Unix"
indent_type = "Spaces"
indent_width = 2
quote_style = "AutoPreferDouble"
call_parentheses = "Always"
collapse_simple_statement = "Never"

[sort_requires]
enabled = true
Loading