rtti.odin 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package flags
  2. import "base:runtime"
  3. /*
  4. Handle setting custom data types.
  5. Inputs:
  6. - data: A raw pointer to the field where the data will go.
  7. - data_type: Type information on the underlying field.
  8. - unparsed_value: The unparsed string that the flag is being set to.
  9. - args_tag: The `args` tag from the struct's field.
  10. Returns:
  11. - error: An error message, or an empty string if no error occurred.
  12. - handled: A boolean indicating if the setter handles this type.
  13. - alloc_error: If an allocation error occurred, return it here.
  14. */
  15. Custom_Type_Setter :: #type proc(
  16. data: rawptr,
  17. data_type: typeid,
  18. unparsed_value: string,
  19. args_tag: string,
  20. ) -> (
  21. error: string,
  22. handled: bool,
  23. alloc_error: runtime.Allocator_Error,
  24. )
  25. @(private)
  26. global_custom_type_setter: Custom_Type_Setter
  27. /*
  28. Set the global custom type setter.
  29. Note that only one can be active at a time.
  30. Inputs:
  31. - setter: The type setter. Pass `nil` to disable any previously set setter.
  32. */
  33. register_type_setter :: proc(setter: Custom_Type_Setter) {
  34. global_custom_type_setter = setter
  35. }