diff options
| author | Zuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian> | 2026-01-17 16:33:36 +0000 |
|---|---|---|
| committer | Zuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian> | 2026-01-17 16:33:36 +0000 |
| commit | 6b2545224752be74de35166c3dcda9ff5bdb79e3 (patch) | |
| tree | aa2765253769a0a1635d9ffc22738ec6598254c1 /examples | |
| parent | b885629239d04d2860a8853799a3d335d8bec154 (diff) | |
Add C++ interop support.
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/cpp_interop.zc | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/examples/cpp_interop.zc b/examples/cpp_interop.zc new file mode 100644 index 0000000..2f2e033 --- /dev/null +++ b/examples/cpp_interop.zc @@ -0,0 +1,36 @@ + +include <vector> +include <iostream> +include <string> + +// C++ helper functions in raw blocks +raw { + std::vector<int> cpp_make_vector(int a, int b, int c) { + return {a, b, c}; + } + + int cpp_sum_vector(std::vector<int>& vec) { + int sum = 0; + for (int x : vec) sum += x; + return sum; + } + + void cpp_print(const char* msg) { + std::cout << "[C++] " << msg << std::endl; + } +} + +fn main() { + "=> Zen C + C++ interop."; + + cpp_print("Hello from C++!"); + + var vec = cpp_make_vector(10, 20, 30); + var result = cpp_sum_vector(vec); + "Sum of C++ vector: {result}"; + + raw { + std::string s = "C++ string: works!"; + std::cout << s << std::endl; + } +} |
