diff --git a/.gitignore b/.gitignore
index 8738970..2bb710e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,10 +1,13 @@
# build
/target
/result
+/dist
# dev env
.direnv
.ccls-cache
+*.d
+*.o
# rpc is a library
Cargo.lock
diff --git a/Cargo.toml b/Cargo.toml
index 94f3356..9991ec3 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -27,3 +27,8 @@ edition = "2021"
crate-type = ["cdylib"]
[dependencies]
+rand = "0.8.5"
+trixy = { path = "../trixy" }
+
+[build-dependencies]
+trixy = { path = "../trixy" }
diff --git a/Makefile b/Makefile
index 8ceba28..c63c85d 100644
--- a/Makefile
+++ b/Makefile
@@ -20,7 +20,7 @@ PREFIX := /usr/local
BINPREFIX := $(DESTDIR)$(PREFIX)/bin
MANPREFIX := $(DESTDIR)$(PREFIX)/share/man/man1
-BIN_NAME := main
+BIN_NAME := ./target/main
SRC := $(wildcard c_src/*.c)
OBJ := $(SRC:.c=.o)
@@ -28,8 +28,8 @@ DEP := $(OBJ:.o=.d)
LIBS := rpc
-ALL_CFLAGS := -fPIC -O3 -MMD -Wall -Wextra -Wno-unused-parameter $(CFLAGS) $(CPPFLAGS)
-ALL_LDFLAGS := -shared $(addprefix -l,$(LIBS)) -L $(LD_LIBRARY_PATH) $(CFLAGS) $(LDFLAGS)
+ALL_CFLAGS := -O3 -MMD -Wall -Wextra -Wno-unused-parameter $(CFLAGS) $(CPPFLAGS)
+ALL_LDFLAGS := $(addprefix -l,$(LIBS)) -L $(LD_LIBRARY_PATH) $(CFLAGS) $(LDFLAGS)
diff --git a/build.rs b/build.rs
index 81808dc..20bfea4 100644
--- a/build.rs
+++ b/build.rs
@@ -18,11 +18,12 @@
* If not, see .
*/
-use trixy_macros::config::TrixyConfig;
+use trixy::macros::config::TrixyConfig;
fn main() {
+ println!("cargo:rerun-if-changed=./dist/*");
println!("cargo:rerun-if-changed=./src/api.tri");
- TrixyConfig::new("callback")
+ TrixyConfig::new("handle_cmd")
.trixy_path("./src/api.tri")
.dist_dir_path("./dist")
.generate_debug(true)
diff --git a/c_src/main.c b/c_src/main.c
index 09e0c44..0804e0f 100644
--- a/c_src/main.c
+++ b/c_src/main.c
@@ -1,20 +1,82 @@
/*
-* Copyright (C) 2023 The Trinitrix Project
-*
-* This file is part of the RPC crate for Trinitrix.
-*
-* RPC is free software: you can redistribute it and/or modify
-* it under the terms of the Lesser GNU General Public License as
-* published by the Free Software Foundation, either version 3 of
-* the License, or (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* and the Lesser GNU General Public License along with this program.
-* If not, see .
-*/
+ * Copyright (C) 2023 The Trinitrix Project
+ *
+ * This file is part of the RPC crate for Trinitrix.
+ *
+ * RPC is free software: you can redistribute it and/or modify
+ * it under the terms of the Lesser GNU General Public License as
+ * published by the Free Software Foundation, either version 3 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * and the Lesser GNU General Public License along with this program.
+ * If not, see .
+ */
+#include "../dist/interface.h"
+#include
+#include
+#include
+#include
+
+int main() {
+ printf("Checking result\n");
+ result_t result;
+ if (!initialize_socket(&result, "hi")) {
+ int error_length = last_error_length();
+ char *buffer = malloc(error_length);
+ last_error_message(buffer, error_length);
+ printf("error: %s\n", buffer);
+ }
+ if (result.tag == ok) {
+ printf("Hurray! Value is: %p\n", result.value);
+ }
+ printf("Type is: %d\n", result.type_id);
+
+ printf("\n\nChecking enum\n");
+ enum_a_t enum_a;
+ if (fn_alone(&enum_a, "hi")) {
+ printf("Call succeded, it returned: %d\n", enum_a);
+ assert(enum_a == Val1);
+ } else {
+ int error_length = last_error_length();
+ char *buffer = malloc(error_length);
+ last_error_message(buffer, error_length);
+ printf("error: %s\n", buffer);
+ };
+
+ printf("\n\nChecking str\n");
+ str_t str;
+ if (one.fn_one(&str)) {
+ printf("Call succeded, it returned: %s\n", str);
+ }
+
+ printf("\n\nChecking string\n");
+ string_t string;
+ if (one.two.fn_two(&string)) {
+ printf("Call succeded, it returned: %s\n", string);
+ }
+ string = strcpy(string, "some other text");
+ printf("String is after the strcpy: %s\n", string);
+ free(string);
+
+ printf("\n\nChecking result with string\n");
+ result_t str_result;
+ if (one.two.three.fn_three(&str_result)) {
+ if (str_result.tag == err) {
+ printf("Call failed, it returned: %s\n", (str_t)str_result.value);
+ } else {
+ printf("Call succeded, it returned: %s\n", (string_t)str_result.value);
+ }
+ printf("Type is: %d\n", str_result.type_id);
+ assert(str_result.type_id == type_string_t);
+ }
+
+ return 0;
+}
diff --git a/src/api.tri b/src/api.tri
new file mode 100644
index 0000000..d68e1fd
--- /dev/null
+++ b/src/api.tri
@@ -0,0 +1,32 @@
+/// Initialize the underlying rpc socket.
+/// This function is not actually part of Trinitrix's API, meaning that only this rpc
+/// library will understand it.
+///
+/// It **must** be called before any other functions, as rpc otherwise won't be able to
+/// talk to Trinitrix
+fn initialize_socket(path: String) -> Result;
+
+enum SocketInitError {
+ Err1,
+ Err2
+};
+
+enum EnumA {
+ Val1,
+};
+
+fn string_to_enum(input: String) -> EnumA;
+
+nasp one {
+ enum Error {
+ Val1,
+ };
+ fn str_to_result(input: str) -> Result;
+ fn vec_to_string(input: Vec) -> String;
+ fn option_to_result(input: Option) -> Result