aboutsummaryrefslogtreecommitdiff
path: root/core/flags/rtti.odin
diff options
context:
space:
mode:
authorFeoramund <161657516+Feoramund@users.noreply.github.com>2024-06-06 18:35:43 -0400
committerFeoramund <161657516+Feoramund@users.noreply.github.com>2024-06-07 13:16:13 -0400
commitedb685f04be9aef407dc8abac7bb76fb51184f9f (patch)
tree63f48c951de7a9d751895a3cd72194e241bd38c0 /core/flags/rtti.odin
parent08612423b9afffb7499d8db2c69715df1627bd50 (diff)
Add package `core:flags`
Diffstat (limited to 'core/flags/rtti.odin')
-rw-r--r--core/flags/rtti.odin43
1 files changed, 43 insertions, 0 deletions
diff --git a/core/flags/rtti.odin b/core/flags/rtti.odin
new file mode 100644
index 000000000..ce7a23773
--- /dev/null
+++ b/core/flags/rtti.odin
@@ -0,0 +1,43 @@
+package flags
+
+import "base:runtime"
+
+/*
+Handle setting custom data types.
+
+Inputs:
+- data: A raw pointer to the field where the data will go.
+- data_type: Type information on the underlying field.
+- unparsed_value: The unparsed string that the flag is being set to.
+- args_tag: The `args` tag from the struct's field.
+
+Returns:
+- error: An error message, or an empty string if no error occurred.
+- handled: A boolean indicating if the setter handles this type.
+- alloc_error: If an allocation error occurred, return it here.
+*/
+Custom_Type_Setter :: #type proc(
+ data: rawptr,
+ data_type: typeid,
+ unparsed_value: string,
+ args_tag: string,
+) -> (
+ error: string,
+ handled: bool,
+ alloc_error: runtime.Allocator_Error,
+)
+
+@(private)
+global_custom_type_setter: Custom_Type_Setter
+
+/*
+Set the global custom type setter.
+
+Note that only one can be active at a time.
+
+Inputs:
+- setter: The type setter. Pass `nil` to disable any previously set setter.
+*/
+register_type_setter :: proc(setter: Custom_Type_Setter) {
+ global_custom_type_setter = setter
+}