summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHenrique Lacreta Alves <henriquelalves@gmail.com>2024-05-14 10:12:39 +0300
committerGitHub <noreply@github.com>2024-05-14 10:12:39 +0300
commit9859882f9f37f3eee6f9b90348c7e3c2ed229c49 (patch)
tree3f89305088b7f14965dce6c15af45b95b3eb0472
parent569c6856d1bc1b873b317a470d8d1591f92568a2 (diff)
parent9999ea36e68e910af8dbf1f8b0c0fc4bf2c3b6a5 (diff)
downloadgamejam-slgj-2024-9859882f9f37f3eee6f9b90348c7e3c2ed229c49.tar.gz
gamejam-slgj-2024-9859882f9f37f3eee6f9b90348c7e3c2ed229c49.tar.bz2
gamejam-slgj-2024-9859882f9f37f3eee6f9b90348c7e3c2ed229c49.zip
Merge pull request #4 from gilzoide/automatic-raylib-enums
Automatic bindings for raylib enums
-rw-r--r--.editorconfig4
-rw-r--r--scripts/keys.scm7
-rw-r--r--scripts/main.scm1
-rw-r--r--sources/main.c2
-rw-r--r--sources/rl/enums.c118
-rw-r--r--sources/rl/enums.h9
-rw-r--r--tools/generate_raylib_enums.py46
7 files changed, 179 insertions, 8 deletions
diff --git a/.editorconfig b/.editorconfig
index 3ab36f3..717e6a1 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -12,3 +12,7 @@ indent_size = 2
[CMake*.txt]
indent_style = space
indent_size = 2
+
+[*.py]
+indent_style = space
+indent_size = 4
diff --git a/scripts/keys.scm b/scripts/keys.scm
deleted file mode 100644
index 83a683c..0000000
--- a/scripts/keys.scm
+++ /dev/null
@@ -1,7 +0,0 @@
-(define KEY_ENTER 257)
-(define KEY_BACKSPACE 259)
-(define KEY_SPACE 32)
-(define KEY_RIGHT 262)
-(define KEY_LEFT 263)
-(define KEY_DOWN 264)
-(define KEY_UP 265)
diff --git a/scripts/main.scm b/scripts/main.scm
index 7480777..af6b550 100644
--- a/scripts/main.scm
+++ b/scripts/main.scm
@@ -1,4 +1,3 @@
-(load "./scripts/keys.scm")
(load "./scripts/structs.scm")
(load "./scripts/utils.scm")
(load "./scripts/prompt.scm")
diff --git a/sources/main.c b/sources/main.c
index 7196bc4..4f899ce 100644
--- a/sources/main.c
+++ b/sources/main.c
@@ -9,6 +9,7 @@
#include "rl/text.h"
#include "rl/texture.h"
#include "rl/core.h"
+#include "rl/enums.h"
#include "rl/shapes.h"
#include "repl/repl.h"
@@ -48,6 +49,7 @@ int main(int argc, char* argv[]) {
s7 = s7_init();
rl_register_types(s7);
+ rl_register_enums(s7);
rl_text_define_methods(s7);
rl_texture_define_methods(s7);
rl_core_define_methods(s7);
diff --git a/sources/rl/enums.c b/sources/rl/enums.c
new file mode 100644
index 0000000..7a055e2
--- /dev/null
+++ b/sources/rl/enums.c
@@ -0,0 +1,118 @@
+// This file was automatically generated by tools/generate_raylib_enums.py
+// Any manual modifications will be overwritten when running the script again
+#include "enums.h"
+#include "raylib.h"
+
+void rl_register_enums(s7_scheme *s7) {
+ // enum KeyboardKey
+ S7_DEFINE_ENUM(s7, KEY_NULL);
+ S7_DEFINE_ENUM(s7, KEY_APOSTROPHE);
+ S7_DEFINE_ENUM(s7, KEY_COMMA);
+ S7_DEFINE_ENUM(s7, KEY_MINUS);
+ S7_DEFINE_ENUM(s7, KEY_PERIOD);
+ S7_DEFINE_ENUM(s7, KEY_SLASH);
+ S7_DEFINE_ENUM(s7, KEY_ZERO);
+ S7_DEFINE_ENUM(s7, KEY_ONE);
+ S7_DEFINE_ENUM(s7, KEY_TWO);
+ S7_DEFINE_ENUM(s7, KEY_THREE);
+ S7_DEFINE_ENUM(s7, KEY_FOUR);
+ S7_DEFINE_ENUM(s7, KEY_FIVE);
+ S7_DEFINE_ENUM(s7, KEY_SIX);
+ S7_DEFINE_ENUM(s7, KEY_SEVEN);
+ S7_DEFINE_ENUM(s7, KEY_EIGHT);
+ S7_DEFINE_ENUM(s7, KEY_NINE);
+ S7_DEFINE_ENUM(s7, KEY_SEMICOLON);
+ S7_DEFINE_ENUM(s7, KEY_EQUAL);
+ S7_DEFINE_ENUM(s7, KEY_A);
+ S7_DEFINE_ENUM(s7, KEY_B);
+ S7_DEFINE_ENUM(s7, KEY_C);
+ S7_DEFINE_ENUM(s7, KEY_D);
+ S7_DEFINE_ENUM(s7, KEY_E);
+ S7_DEFINE_ENUM(s7, KEY_F);
+ S7_DEFINE_ENUM(s7, KEY_G);
+ S7_DEFINE_ENUM(s7, KEY_H);
+ S7_DEFINE_ENUM(s7, KEY_I);
+ S7_DEFINE_ENUM(s7, KEY_J);
+ S7_DEFINE_ENUM(s7, KEY_K);
+ S7_DEFINE_ENUM(s7, KEY_L);
+ S7_DEFINE_ENUM(s7, KEY_M);
+ S7_DEFINE_ENUM(s7, KEY_N);
+ S7_DEFINE_ENUM(s7, KEY_O);
+ S7_DEFINE_ENUM(s7, KEY_P);
+ S7_DEFINE_ENUM(s7, KEY_Q);
+ S7_DEFINE_ENUM(s7, KEY_R);
+ S7_DEFINE_ENUM(s7, KEY_S);
+ S7_DEFINE_ENUM(s7, KEY_T);
+ S7_DEFINE_ENUM(s7, KEY_U);
+ S7_DEFINE_ENUM(s7, KEY_V);
+ S7_DEFINE_ENUM(s7, KEY_W);
+ S7_DEFINE_ENUM(s7, KEY_X);
+ S7_DEFINE_ENUM(s7, KEY_Y);
+ S7_DEFINE_ENUM(s7, KEY_Z);
+ S7_DEFINE_ENUM(s7, KEY_LEFT_BRACKET);
+ S7_DEFINE_ENUM(s7, KEY_BACKSLASH);
+ S7_DEFINE_ENUM(s7, KEY_RIGHT_BRACKET);
+ S7_DEFINE_ENUM(s7, KEY_GRAVE);
+ S7_DEFINE_ENUM(s7, KEY_SPACE);
+ S7_DEFINE_ENUM(s7, KEY_ESCAPE);
+ S7_DEFINE_ENUM(s7, KEY_ENTER);
+ S7_DEFINE_ENUM(s7, KEY_TAB);
+ S7_DEFINE_ENUM(s7, KEY_BACKSPACE);
+ S7_DEFINE_ENUM(s7, KEY_INSERT);
+ S7_DEFINE_ENUM(s7, KEY_DELETE);
+ S7_DEFINE_ENUM(s7, KEY_RIGHT);
+ S7_DEFINE_ENUM(s7, KEY_LEFT);
+ S7_DEFINE_ENUM(s7, KEY_DOWN);
+ S7_DEFINE_ENUM(s7, KEY_UP);
+ S7_DEFINE_ENUM(s7, KEY_PAGE_UP);
+ S7_DEFINE_ENUM(s7, KEY_PAGE_DOWN);
+ S7_DEFINE_ENUM(s7, KEY_HOME);
+ S7_DEFINE_ENUM(s7, KEY_END);
+ S7_DEFINE_ENUM(s7, KEY_CAPS_LOCK);
+ S7_DEFINE_ENUM(s7, KEY_SCROLL_LOCK);
+ S7_DEFINE_ENUM(s7, KEY_NUM_LOCK);
+ S7_DEFINE_ENUM(s7, KEY_PRINT_SCREEN);
+ S7_DEFINE_ENUM(s7, KEY_PAUSE);
+ S7_DEFINE_ENUM(s7, KEY_F1);
+ S7_DEFINE_ENUM(s7, KEY_F2);
+ S7_DEFINE_ENUM(s7, KEY_F3);
+ S7_DEFINE_ENUM(s7, KEY_F4);
+ S7_DEFINE_ENUM(s7, KEY_F5);
+ S7_DEFINE_ENUM(s7, KEY_F6);
+ S7_DEFINE_ENUM(s7, KEY_F7);
+ S7_DEFINE_ENUM(s7, KEY_F8);
+ S7_DEFINE_ENUM(s7, KEY_F9);
+ S7_DEFINE_ENUM(s7, KEY_F10);
+ S7_DEFINE_ENUM(s7, KEY_F11);
+ S7_DEFINE_ENUM(s7, KEY_F12);
+ S7_DEFINE_ENUM(s7, KEY_LEFT_SHIFT);
+ S7_DEFINE_ENUM(s7, KEY_LEFT_CONTROL);
+ S7_DEFINE_ENUM(s7, KEY_LEFT_ALT);
+ S7_DEFINE_ENUM(s7, KEY_LEFT_SUPER);
+ S7_DEFINE_ENUM(s7, KEY_RIGHT_SHIFT);
+ S7_DEFINE_ENUM(s7, KEY_RIGHT_CONTROL);
+ S7_DEFINE_ENUM(s7, KEY_RIGHT_ALT);
+ S7_DEFINE_ENUM(s7, KEY_RIGHT_SUPER);
+ S7_DEFINE_ENUM(s7, KEY_KB_MENU);
+ S7_DEFINE_ENUM(s7, KEY_KP_0);
+ S7_DEFINE_ENUM(s7, KEY_KP_1);
+ S7_DEFINE_ENUM(s7, KEY_KP_2);
+ S7_DEFINE_ENUM(s7, KEY_KP_3);
+ S7_DEFINE_ENUM(s7, KEY_KP_4);
+ S7_DEFINE_ENUM(s7, KEY_KP_5);
+ S7_DEFINE_ENUM(s7, KEY_KP_6);
+ S7_DEFINE_ENUM(s7, KEY_KP_7);
+ S7_DEFINE_ENUM(s7, KEY_KP_8);
+ S7_DEFINE_ENUM(s7, KEY_KP_9);
+ S7_DEFINE_ENUM(s7, KEY_KP_DECIMAL);
+ S7_DEFINE_ENUM(s7, KEY_KP_DIVIDE);
+ S7_DEFINE_ENUM(s7, KEY_KP_MULTIPLY);
+ S7_DEFINE_ENUM(s7, KEY_KP_SUBTRACT);
+ S7_DEFINE_ENUM(s7, KEY_KP_ADD);
+ S7_DEFINE_ENUM(s7, KEY_KP_ENTER);
+ S7_DEFINE_ENUM(s7, KEY_KP_EQUAL);
+ S7_DEFINE_ENUM(s7, KEY_BACK);
+ S7_DEFINE_ENUM(s7, KEY_MENU);
+ S7_DEFINE_ENUM(s7, KEY_VOLUME_UP);
+ S7_DEFINE_ENUM(s7, KEY_VOLUME_DOWN);
+}
diff --git a/sources/rl/enums.h b/sources/rl/enums.h
new file mode 100644
index 0000000..02b779c
--- /dev/null
+++ b/sources/rl/enums.h
@@ -0,0 +1,9 @@
+#pragma once
+
+#include "s7/s7.h"
+
+/// Defines an enum in s7 with the same name and value as in C
+#define S7_DEFINE_ENUM(s7, x) \
+ s7_define_variable(s7, #x, s7_make_integer(s7, x))
+
+void rl_register_enums(s7_scheme *s7);
diff --git a/tools/generate_raylib_enums.py b/tools/generate_raylib_enums.py
new file mode 100644
index 0000000..6701b78
--- /dev/null
+++ b/tools/generate_raylib_enums.py
@@ -0,0 +1,46 @@
+"""
+Generates raylib enum bindings from C to s7
+"""
+
+import json
+from os import path
+
+
+# List of enums that will be included in the generated file
+# Change this and re-run the script to add more enum bindings
+INCLUDE_ENUMS = [
+ "KeyboardKey",
+]
+
+
+def main():
+ input_path = path.join(path.dirname(__file__), "..", "libs", "raylib", "parser", "output", "raylib_api.json")
+ output_path = path.join(path.dirname(__file__), "..", "sources", "rl", "enums.c")
+ with open(input_path, "r") as input_file:
+ raylib_api = json.load(input_file)
+ with open(output_path, "w") as output_file:
+ def writelines(*lines):
+ output_file.writelines(line + "\n" for line in lines)
+ writelines(
+ "// This file was automatically generated by tools/generate_raylib_enums.py",
+ "// Any manual modifications will be overwritten when running the script again",
+ "#include \"enums.h\"",
+ "#include \"raylib.h\"",
+ "",
+ "void rl_register_enums(s7_scheme *s7) {",
+ )
+ for enum in raylib_api["enums"]:
+ if enum["name"] not in INCLUDE_ENUMS:
+ continue
+ writelines(
+ f" // enum {enum['name']}",
+ *[
+ f" S7_DEFINE_ENUM(s7, {value['name']});"
+ for value in enum["values"]
+ ],
+ )
+ writelines("}")
+
+
+if __name__ == "__main__":
+ main()