From 9f441ed8f7ecfb8c261546632b40f670337595bf Mon Sep 17 00:00:00 2001 From: disarray2077 <86157825+disarray2077@users.noreply.github.com> Date: Fri, 4 Mar 2022 13:50:34 -0300 Subject: [PATCH] Add `AllocOwned` to `Variant` --- BeefLibs/corlib/src/Variant.bf | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/BeefLibs/corlib/src/Variant.bf b/BeefLibs/corlib/src/Variant.bf index 825b5f96..0aed61ad 100644 --- a/BeefLibs/corlib/src/Variant.bf +++ b/BeefLibs/corlib/src/Variant.bf @@ -265,6 +265,23 @@ namespace System } } + public static void* AllocOwned(Type type, out Variant variant) + { + variant = .(); + + if (type.IsObject) + { + return &variant.mData; + } + else + { + variant.mStructType = (int)Internal.UnsafeCastToPtr(type) | 1; + void* data = new uint8[type.[Friend]mSize]*; + variant.mData = (int)data; + return data; + } + } + public T Get() where T : class { Debug.Assert(IsObject);