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:
parent
c21be1eea1
commit
2f98e7f579
7 changed files with 72 additions and 26 deletions
32
IDEHelper/Tests/src/Opaques.bf
Normal file
32
IDEHelper/Tests/src/Opaques.bf
Normal 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);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue