summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorgilzoide <gilzoide@gmail.com>2024-05-05 11:04:48 -0300
committergilzoide <gilzoide@gmail.com>2024-05-05 11:08:42 -0300
commit9999ea36e68e910af8dbf1f8b0c0fc4bf2c3b6a5 (patch)
tree3f89305088b7f14965dce6c15af45b95b3eb0472 /tools
parentd78391bcf9d9730a70298c39871b60314629ed66 (diff)
downloadgamejam-slgj-2024-9999ea36e68e910af8dbf1f8b0c0fc4bf2c3b6a5.tar.gz
gamejam-slgj-2024-9999ea36e68e910af8dbf1f8b0c0fc4bf2c3b6a5.tar.bz2
gamejam-slgj-2024-9999ea36e68e910af8dbf1f8b0c0fc4bf2c3b6a5.zip
Add script for automatically generating enums.c from raylib_api.json
Diffstat (limited to 'tools')
-rw-r--r--tools/generate_raylib_enums.py46
1 files changed, 46 insertions, 0 deletions
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()