Skip to content

Lua: initial implementation of a service based approach#295

Merged
Peefy merged 1 commit into
kcl-lang:mainfrom
f4z3r:test/service-api
May 9, 2026
Merged

Lua: initial implementation of a service based approach#295
Peefy merged 1 commit into
kcl-lang:mainfrom
f4z3r:test/service-api

Conversation

@f4z3r
Copy link
Copy Markdown
Contributor

@f4z3r f4z3r commented May 8, 2026

This exposes a low level raw API to the native service running over protobuf. Another highler level API is provided with more ergonomic functions based on the low level API for simpler use of the SDK.

1. Does this PR affect any open issues?(Y/N) and add issue references (e.g. "fix #123", "re #123".):

  • N
  • Y

kcl-lang/kcl#388

2. What is the scope of this PR (e.g. component or file name):

The Lua SDK.

3. Provide a description of the PR(e.g. more details, effects, motivations or doc link):

It modifies the structure of the SDK to minimize the amount of Rust code needed and uses a native service call interface over protobuf similar to the implementation in Python and Go.

The raw native API is not yet extended to support all methods. On top of the raw native API, an ergonomic Lua API provides convenience methods to work with KCL.

4. Are there any breaking changes?(Y/N) and describe the breaking changes(e.g. more details, motivations or doc link):

  • N
  • Y

The API changes.

5. Are there test cases for these changes?(Y/N) select and add more details, references or doc links:

  • Unit test
  • Integration test
  • Benchmark (add benchmark stats below)
  • Manual test (add detailed scripts or steps below)
  • Other

Comment thread lua/kcl_lib/schema.lua
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that I generate the binary protobuf directly into Lua to facilitate how it can be shipped with Luarocks.

Comment thread lua/kcl_lib/raw_api.lua
self.pb.encode(arg_type, args),
"failed to encode argument into " .. arg_type
)
local res = assert(
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that I use very defensive programming here. This might not be desired if you want to propagate errors to the users. I currently implemented this so that the errors are easier to pin-point.

Comment thread lua/kcl_lib/raw_api.lua
add_method("KclService.ExecProgram", "ExecProgramArgs", "ExecProgramResult")

RawAPI.format_path =
add_method("KclService.FormatPath", "FormatPathArgs", "FormatPathResult")
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional functions can be added by a single line like this in the future. I will do this in a second PR if this is accepted to support all the functions in the SDK.

This exposes a low level raw API to the native service running over
protobuf. Another highler level API is provided with more ergonomic
functions based on the low level API for simpler use of the SDK.

Signed-off-by: Jakob Beckmann <f4z3r-github@pm.me>
@f4z3r f4z3r force-pushed the test/service-api branch from 5e8a5e1 to 9507499 Compare May 8, 2026 15:46
@Peefy Peefy merged commit bfb3e7f into kcl-lang:main May 9, 2026
8 of 9 checks passed
@f4z3r f4z3r deleted the test/service-api branch May 9, 2026 07:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants