aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorUneven Prankster <unevenprankster@protonmail.com>2023-07-12 21:05:57 -0300
committerUneven Prankster <unevenprankster@protonmail.com>2023-07-12 21:05:57 -0300
commit111c133b939c15c57c90cd474d55e84928c6307a (patch)
tree3e6ed21eaaf21a8f8f4c5c9933972ea476d37b8e /src
parentfa2bdd711212ba6b7a94a20971e8bfa281e73296 (diff)
Officially past the point of no return. C scripting works!
Diffstat (limited to 'src')
-rw-r--r--src/main.c3
-rw-r--r--src/script_sys.c33
-rw-r--r--src/script_sys.h5
3 files changed, 41 insertions, 0 deletions
diff --git a/src/main.c b/src/main.c
index 9bcf6f1..d6686c3 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1,6 +1,7 @@
#include <raylib.h>
#include "texture_sys.h"
#include "shader_sys.h"
+#include "script_sys.h"
int main()
{
@@ -10,6 +11,7 @@ int main()
init_tex_sys();
init_shader_sys();
+ init_script_sys();
int femme = load_new_tex("assets/femme.png");
int grayscale = load_new_shader("assets/gs_full.glsl");
@@ -25,6 +27,7 @@ int main()
EndDrawing();
}
+ deinit_script_sys();
unload_active_textures();
unload_active_shaders();
diff --git a/src/script_sys.c b/src/script_sys.c
new file mode 100644
index 0000000..047ba8a
--- /dev/null
+++ b/src/script_sys.c
@@ -0,0 +1,33 @@
+#include "script_sys.h"
+
+#include <libtcc.h>
+#include <stddef.h>
+#include <stdio.h>
+
+TCCState* state = NULL;
+
+int goob(void)
+{
+ return 255;
+}
+
+void init_script_sys(void)
+{
+ state = tcc_new();
+ tcc_set_output_type(state, TCC_OUTPUT_MEMORY);
+
+ tcc_add_symbol(state, "goob", goob);
+
+ tcc_add_file(state, "assets/src/main.c");
+
+ tcc_relocate(state, TCC_RELOCATE_AUTO);
+
+ int(*const test)() = tcc_get_symbol(state, "test");
+ printf("Result: %i\n", test());
+}
+
+void deinit_script_sys(void)
+{
+ tcc_delete(state);
+ state = NULL;
+} \ No newline at end of file
diff --git a/src/script_sys.h b/src/script_sys.h
new file mode 100644
index 0000000..146ed04
--- /dev/null
+++ b/src/script_sys.h
@@ -0,0 +1,5 @@
+#pragma once
+
+void init_script_sys(void);
+
+void deinit_script_sys(void); \ No newline at end of file