From 44b6e4c222673f5e10d9393aadd87ceec4d2bda6 Mon Sep 17 00:00:00 2001 From: Synthasmagoria Date: Tue, 26 May 2026 13:33:17 +0000 Subject: [PATCH] Add README.md --- README.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..2a94e72 --- /dev/null +++ b/README.md @@ -0,0 +1,25 @@ +# Generate reflection code for GML enums +Check out this article for why you might want to do this: https://synthasmagoria.github.io/error_handling_in_gm/ + +The program generates a few functions that make it possible to retreive the names of enums and enum members. +To tell the program to generate reflection for a specific enum add `gml_pragma("enum_reflection")` on the line before. +```ts +/* This file was generated using enum_reflection tool */ +enum Enum { CoolError, _Count } +global._ENUM_NAMES = [ "CoolError", ]; +global._ENUM_MEMBER_NAMES = [ + ["Bad", "Bad2", "Bad3"], +]; +function enum_get_name(index) { + return global._ENUM_NAMES[index]; +} +function enum_get_member_name(index, member) { + return global._ENUM_MEMBER_NAMES[index][member]; +} +function enum_get_member_names(index) { + return global._ENUM_MEMBER_NAMES[index]; +} +function enum_get_member_name_full(index, member) { + return $"{global._ENUM_NAMES[index]}.{global._ENUM_MEMBER_NAMES[index][member]}"; +} +``` \ No newline at end of file