From 0b064765c913aeb4e6938e7fa3094f2d60507181 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Fri, 17 Mar 2023 11:47:39 +0000 Subject: [PATCH] Add `reflect.struct_field_value` --- core/reflect/reflect.odin | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/core/reflect/reflect.odin b/core/reflect/reflect.odin index 2abf450fa..f8343ead2 100644 --- a/core/reflect/reflect.odin +++ b/core/reflect/reflect.odin @@ -449,7 +449,14 @@ struct_field_value_by_name :: proc(a: any, field: string, allow_using := false) 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) struct_field_names :: proc(T: typeid) -> []string {