Browse Source

Add `reflect.struct_field_value`

gingerBill 2 years ago
parent
commit
0b064765c9
1 changed files with 8 additions and 1 deletions
  1. 8 1
      core/reflect/reflect.odin

+ 8 - 1
core/reflect/reflect.odin

@@ -449,7 +449,14 @@ struct_field_value_by_name :: proc(a: any, field: string, allow_using := false)
 	return nil
 	return nil
 }
 }
 
 
-
+@(require_results)
+struct_field_value :: proc(a: any, field: Struct_Field) -> any {
+	if a == nil { return nil }
+	return any {
+		rawptr(uintptr(a.data) + field.offset),
+		field.type.id,
+	}
+}
 
 
 @(require_results)
 @(require_results)
 struct_field_names :: proc(T: typeid) -> []string {
 struct_field_names :: proc(T: typeid) -> []string {