diff --git a/docs/reference/xlang-api/c-api.md b/docs/reference/xlang-api/c-api.md index 21a35d4e..dea5cb25 100644 --- a/docs/reference/xlang-api/c-api.md +++ b/docs/reference/xlang-api/c-api.md @@ -105,7 +105,7 @@ Validate code using schema and JSON/YAML data strings.
Example

-```rust +```c #include int validate(const char* code_str, const char* data_str) diff --git a/docs/reference/xlang-api/cpp-api.md b/docs/reference/xlang-api/cpp-api.md index 6173f76c..4673fb98 100644 --- a/docs/reference/xlang-api/cpp-api.md +++ b/docs/reference/xlang-api/cpp-api.md @@ -80,7 +80,7 @@ Validate code using schema and JSON/YAML data strings.

Example

-```rust +```cpp #include "kcl_lib.hpp" #include @@ -113,3 +113,136 @@ int main()

+ +### override_file + +Override KCL file with arguments. See [https://www.kcl-lang.io/docs/user_docs/guides/automation](https://www.kcl-lang.io/docs/user_docs/guides/automation) for more override spec guide. + +
Example +

+ +The content of `main.k` is + +```c++ +a = 1 + +b = { + "a": 1 + "b": 2 +} +``` + +C++ Code + +```cpp +#include "kcl_lib.hpp" +#include + +int main() +{ + auto args = kcl_lib::OverrideFileArgs { + .file = rust::String("main.k"), + .specs = rust::Vec({ rust::String("b.a=2") }), + }; + auto result = kcl_lib::override_file(args); + std::cout << result.result << std::endl; + std::cout << result.parse_errors.size() << std::endl; + return 0; +} +``` + +

+
+ +### update_dependencies + +Download and update dependencies defined in the `kcl.mod` file and return the external package name and location list. + +
Example +

+ +The content of `module/kcl.mod` is + +```yaml +[package] +name = "mod_update" +edition = "0.0.1" +version = "0.0.1" + +[dependencies] +helloworld = { oci = "oci://ghcr.io/kcl-lang/helloworld", tag = "0.1.0" } +flask = { git = "https://github.com/kcl-lang/flask-demo-kcl-manifests", commit = "ade147b" } +``` + +C++ Code + +```c++ +#include "kcl_lib.hpp" +#include + +int main() +{ + auto args = kcl_lib::UpdateDependenciesArgs { + .manifest_path = rust::String("../test_data/update_dependencies"), + }; + auto result = kcl_lib::update_dependencies(args); + std::cout << result.external_pkgs[0].pkg_name.c_str() << std::endl; + std::cout << result.external_pkgs[1].pkg_name.c_str() << std::endl; + return 0; +} +``` + +

+
+ +Call `exec_program` with external dependencies + +
Example +

+ +The content of `module/kcl.mod` is + +```yaml +[package] +name = "mod_update" +edition = "0.0.1" +version = "0.0.1" + +[dependencies] +helloworld = { oci = "oci://ghcr.io/kcl-lang/helloworld", tag = "0.1.0" } +flask = { git = "https://github.com/kcl-lang/flask-demo-kcl-manifests", commit = "ade147b" } +``` + +The content of `module/main.k` is + +```c++ +import helloworld +import flask + +a = helloworld.The_first_kcl_program +``` + +C++ Code + +```c++ +#include "kcl_lib.hpp" +#include + +int main() +{ + auto args = kcl_lib::UpdateDependenciesArgs { + .manifest_path = rust::String("../test_data/update_dependencies"), + }; + auto result = kcl_lib::update_dependencies(args); + auto exec_args = kcl_lib::ExecProgramArgs { + .k_filename_list = rust::Vec({ rust::String("../test_data/update_dependencies/main.k") }), + .external_pkgs = result.external_pkgs, + }; + auto exec_result = kcl_lib::exec_program(exec_args); + std::cout << exec_result.yaml_result.c_str() << std::endl; + return 0; +} +``` + +

+
diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/reference/xlang-api/c-api.md b/i18n/zh-CN/docusaurus-plugin-content-docs/current/reference/xlang-api/c-api.md index 55259822..5bfe4678 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/current/reference/xlang-api/c-api.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/reference/xlang-api/c-api.md @@ -105,7 +105,7 @@ Validate code using schema and JSON/YAML data strings.
Example

-```rust +```c #include int validate(const char* code_str, const char* data_str) diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/reference/xlang-api/cpp-api.md b/i18n/zh-CN/docusaurus-plugin-content-docs/current/reference/xlang-api/cpp-api.md index 820f8336..628d20d1 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/current/reference/xlang-api/cpp-api.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/reference/xlang-api/cpp-api.md @@ -80,7 +80,7 @@ Validate code using schema and JSON/YAML data strings.

Example

-```rust +```cpp #include "kcl_lib.hpp" #include @@ -113,3 +113,136 @@ int main()

+ +### override_file + +Override KCL file with arguments. See [https://www.kcl-lang.io/docs/user_docs/guides/automation](https://www.kcl-lang.io/docs/user_docs/guides/automation) for more override spec guide. + +
Example +

+ +The content of `main.k` is + +```c++ +a = 1 + +b = { + "a": 1 + "b": 2 +} +``` + +C++ Code + +```cpp +#include "kcl_lib.hpp" +#include + +int main() +{ + auto args = kcl_lib::OverrideFileArgs { + .file = rust::String("main.k"), + .specs = rust::Vec({ rust::String("b.a=2") }), + }; + auto result = kcl_lib::override_file(args); + std::cout << result.result << std::endl; + std::cout << result.parse_errors.size() << std::endl; + return 0; +} +``` + +

+
+ +### update_dependencies + +Download and update dependencies defined in the `kcl.mod` file and return the external package name and location list. + +
Example +

+ +The content of `module/kcl.mod` is + +```yaml +[package] +name = "mod_update" +edition = "0.0.1" +version = "0.0.1" + +[dependencies] +helloworld = { oci = "oci://ghcr.io/kcl-lang/helloworld", tag = "0.1.0" } +flask = { git = "https://github.com/kcl-lang/flask-demo-kcl-manifests", commit = "ade147b" } +``` + +C++ Code + +```c++ +#include "kcl_lib.hpp" +#include + +int main() +{ + auto args = kcl_lib::UpdateDependenciesArgs { + .manifest_path = rust::String("../test_data/update_dependencies"), + }; + auto result = kcl_lib::update_dependencies(args); + std::cout << result.external_pkgs[0].pkg_name.c_str() << std::endl; + std::cout << result.external_pkgs[1].pkg_name.c_str() << std::endl; + return 0; +} +``` + +

+
+ +Call `exec_program` with external dependencies + +
Example +

+ +The content of `module/kcl.mod` is + +```yaml +[package] +name = "mod_update" +edition = "0.0.1" +version = "0.0.1" + +[dependencies] +helloworld = { oci = "oci://ghcr.io/kcl-lang/helloworld", tag = "0.1.0" } +flask = { git = "https://github.com/kcl-lang/flask-demo-kcl-manifests", commit = "ade147b" } +``` + +The content of `module/main.k` is + +```c++ +import helloworld +import flask + +a = helloworld.The_first_kcl_program +``` + +C++ Code + +```c++ +#include "kcl_lib.hpp" +#include + +int main() +{ + auto args = kcl_lib::UpdateDependenciesArgs { + .manifest_path = rust::String("../test_data/update_dependencies"), + }; + auto result = kcl_lib::update_dependencies(args); + auto exec_args = kcl_lib::ExecProgramArgs { + .k_filename_list = rust::Vec({ rust::String("../test_data/update_dependencies/main.k") }), + .external_pkgs = result.external_pkgs, + }; + auto exec_result = kcl_lib::exec_program(exec_args); + std::cout << exec_result.yaml_result.c_str() << std::endl; + return 0; +} +``` + +

+
diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-0.9/reference/xlang-api/c-api.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-0.9/reference/xlang-api/c-api.md index 55259822..5bfe4678 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-0.9/reference/xlang-api/c-api.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-0.9/reference/xlang-api/c-api.md @@ -105,7 +105,7 @@ Validate code using schema and JSON/YAML data strings.
Example

-```rust +```c #include int validate(const char* code_str, const char* data_str) diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-0.9/reference/xlang-api/cpp-api.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-0.9/reference/xlang-api/cpp-api.md index 820f8336..628d20d1 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-0.9/reference/xlang-api/cpp-api.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-0.9/reference/xlang-api/cpp-api.md @@ -80,7 +80,7 @@ Validate code using schema and JSON/YAML data strings.

Example

-```rust +```cpp #include "kcl_lib.hpp" #include @@ -113,3 +113,136 @@ int main()

+ +### override_file + +Override KCL file with arguments. See [https://www.kcl-lang.io/docs/user_docs/guides/automation](https://www.kcl-lang.io/docs/user_docs/guides/automation) for more override spec guide. + +
Example +

+ +The content of `main.k` is + +```c++ +a = 1 + +b = { + "a": 1 + "b": 2 +} +``` + +C++ Code + +```cpp +#include "kcl_lib.hpp" +#include + +int main() +{ + auto args = kcl_lib::OverrideFileArgs { + .file = rust::String("main.k"), + .specs = rust::Vec({ rust::String("b.a=2") }), + }; + auto result = kcl_lib::override_file(args); + std::cout << result.result << std::endl; + std::cout << result.parse_errors.size() << std::endl; + return 0; +} +``` + +

+
+ +### update_dependencies + +Download and update dependencies defined in the `kcl.mod` file and return the external package name and location list. + +
Example +

+ +The content of `module/kcl.mod` is + +```yaml +[package] +name = "mod_update" +edition = "0.0.1" +version = "0.0.1" + +[dependencies] +helloworld = { oci = "oci://ghcr.io/kcl-lang/helloworld", tag = "0.1.0" } +flask = { git = "https://github.com/kcl-lang/flask-demo-kcl-manifests", commit = "ade147b" } +``` + +C++ Code + +```c++ +#include "kcl_lib.hpp" +#include + +int main() +{ + auto args = kcl_lib::UpdateDependenciesArgs { + .manifest_path = rust::String("../test_data/update_dependencies"), + }; + auto result = kcl_lib::update_dependencies(args); + std::cout << result.external_pkgs[0].pkg_name.c_str() << std::endl; + std::cout << result.external_pkgs[1].pkg_name.c_str() << std::endl; + return 0; +} +``` + +

+
+ +Call `exec_program` with external dependencies + +
Example +

+ +The content of `module/kcl.mod` is + +```yaml +[package] +name = "mod_update" +edition = "0.0.1" +version = "0.0.1" + +[dependencies] +helloworld = { oci = "oci://ghcr.io/kcl-lang/helloworld", tag = "0.1.0" } +flask = { git = "https://github.com/kcl-lang/flask-demo-kcl-manifests", commit = "ade147b" } +``` + +The content of `module/main.k` is + +```c++ +import helloworld +import flask + +a = helloworld.The_first_kcl_program +``` + +C++ Code + +```c++ +#include "kcl_lib.hpp" +#include + +int main() +{ + auto args = kcl_lib::UpdateDependenciesArgs { + .manifest_path = rust::String("../test_data/update_dependencies"), + }; + auto result = kcl_lib::update_dependencies(args); + auto exec_args = kcl_lib::ExecProgramArgs { + .k_filename_list = rust::Vec({ rust::String("../test_data/update_dependencies/main.k") }), + .external_pkgs = result.external_pkgs, + }; + auto exec_result = kcl_lib::exec_program(exec_args); + std::cout << exec_result.yaml_result.c_str() << std::endl; + return 0; +} +``` + +

+
diff --git a/versioned_docs/version-0.9/reference/xlang-api/c-api.md b/versioned_docs/version-0.9/reference/xlang-api/c-api.md index 21a35d4e..dea5cb25 100644 --- a/versioned_docs/version-0.9/reference/xlang-api/c-api.md +++ b/versioned_docs/version-0.9/reference/xlang-api/c-api.md @@ -105,7 +105,7 @@ Validate code using schema and JSON/YAML data strings.
Example

-```rust +```c #include int validate(const char* code_str, const char* data_str) diff --git a/versioned_docs/version-0.9/reference/xlang-api/cpp-api.md b/versioned_docs/version-0.9/reference/xlang-api/cpp-api.md index 6173f76c..4673fb98 100644 --- a/versioned_docs/version-0.9/reference/xlang-api/cpp-api.md +++ b/versioned_docs/version-0.9/reference/xlang-api/cpp-api.md @@ -80,7 +80,7 @@ Validate code using schema and JSON/YAML data strings.

Example

-```rust +```cpp #include "kcl_lib.hpp" #include @@ -113,3 +113,136 @@ int main()

+ +### override_file + +Override KCL file with arguments. See [https://www.kcl-lang.io/docs/user_docs/guides/automation](https://www.kcl-lang.io/docs/user_docs/guides/automation) for more override spec guide. + +
Example +

+ +The content of `main.k` is + +```c++ +a = 1 + +b = { + "a": 1 + "b": 2 +} +``` + +C++ Code + +```cpp +#include "kcl_lib.hpp" +#include + +int main() +{ + auto args = kcl_lib::OverrideFileArgs { + .file = rust::String("main.k"), + .specs = rust::Vec({ rust::String("b.a=2") }), + }; + auto result = kcl_lib::override_file(args); + std::cout << result.result << std::endl; + std::cout << result.parse_errors.size() << std::endl; + return 0; +} +``` + +

+
+ +### update_dependencies + +Download and update dependencies defined in the `kcl.mod` file and return the external package name and location list. + +
Example +

+ +The content of `module/kcl.mod` is + +```yaml +[package] +name = "mod_update" +edition = "0.0.1" +version = "0.0.1" + +[dependencies] +helloworld = { oci = "oci://ghcr.io/kcl-lang/helloworld", tag = "0.1.0" } +flask = { git = "https://github.com/kcl-lang/flask-demo-kcl-manifests", commit = "ade147b" } +``` + +C++ Code + +```c++ +#include "kcl_lib.hpp" +#include + +int main() +{ + auto args = kcl_lib::UpdateDependenciesArgs { + .manifest_path = rust::String("../test_data/update_dependencies"), + }; + auto result = kcl_lib::update_dependencies(args); + std::cout << result.external_pkgs[0].pkg_name.c_str() << std::endl; + std::cout << result.external_pkgs[1].pkg_name.c_str() << std::endl; + return 0; +} +``` + +

+
+ +Call `exec_program` with external dependencies + +
Example +

+ +The content of `module/kcl.mod` is + +```yaml +[package] +name = "mod_update" +edition = "0.0.1" +version = "0.0.1" + +[dependencies] +helloworld = { oci = "oci://ghcr.io/kcl-lang/helloworld", tag = "0.1.0" } +flask = { git = "https://github.com/kcl-lang/flask-demo-kcl-manifests", commit = "ade147b" } +``` + +The content of `module/main.k` is + +```c++ +import helloworld +import flask + +a = helloworld.The_first_kcl_program +``` + +C++ Code + +```c++ +#include "kcl_lib.hpp" +#include + +int main() +{ + auto args = kcl_lib::UpdateDependenciesArgs { + .manifest_path = rust::String("../test_data/update_dependencies"), + }; + auto result = kcl_lib::update_dependencies(args); + auto exec_args = kcl_lib::ExecProgramArgs { + .k_filename_list = rust::Vec({ rust::String("../test_data/update_dependencies/main.k") }), + .external_pkgs = result.external_pkgs, + }; + auto exec_result = kcl_lib::exec_program(exec_args); + std::cout << exec_result.yaml_result.c_str() << std::endl; + return 0; +} +``` + +

+