1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-23 18:18:00 +02:00

Improved opaques - can now be used with extension methods

This commit is contained in:
Brian Fiete 2025-01-19 07:02:18 -08:00
parent c21be1eea1
commit 2f98e7f579
7 changed files with 72 additions and 26 deletions

View file

@ -0,0 +1,32 @@
using System;
namespace Tests;
class Opaques
{
struct StructA
{
public int mA;
public int mB;
}
struct StructB;
public static void Modify(this ref StructB @this, int addA, int addB)
{
StructB* sbPtr = &@this;
StructA* saPtr = (.)(void*)sbPtr;
saPtr.mA += addA;
saPtr.mB += addB;
}
[Test]
public static void TestBasics()
{
StructA sa = .() { mA = 123, mB = 234 };
StructB* sb = (.)&sa;
sb.Modify(1000, 2000);
Test.Assert(sa.mA == 1123);
Test.Assert(sa.mB == 2234);
}
}