Skip to content

Commit 2042b07

Browse files
Support deriving from classes that don't have a default constructor
1 parent 754c23a commit 2042b07

6 files changed

Lines changed: 1358 additions & 270 deletions

File tree

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,6 @@ Note that the code generator does not support (yet):
202202
* `Array` methods (e.g. `IndexOf`)
203203
* `string` methods (e.g. `Substring`)
204204
* Default parameters
205-
* Deriving from classes without a default constructor
206205
* `decimal`
207206
* C# pointers
208207

Unity/Assets/NativeScript/Bindings.cs

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,8 @@ delegate void InitDelegate(
379379
IntPtr boxPrimitiveType,
380380
IntPtr unboxPrimitiveType,
381381
IntPtr unityEngineTimePropertyGetDeltaTime,
382+
IntPtr boxFileMode,
383+
IntPtr unboxFileMode,
382384
IntPtr releaseSystemCollectionsGenericIComparerSystemInt32,
383385
IntPtr systemCollectionsGenericIComparerSystemInt32Constructor,
384386
IntPtr releaseSystemCollectionsGenericIComparerSystemString,
@@ -393,6 +395,8 @@ delegate void InitDelegate(
393395
IntPtr systemCollectionsQueueConstructor,
394396
IntPtr releaseSystemComponentModelDesignIComponentChangeService,
395397
IntPtr systemComponentModelDesignIComponentChangeServiceConstructor,
398+
IntPtr releaseSystemIOFileStream,
399+
IntPtr systemIOFileStreamConstructorSystemString_SystemIOFileMode,
396400
IntPtr boxBoolean,
397401
IntPtr unboxBoolean,
398402
IntPtr boxSByte,
@@ -637,6 +641,9 @@ IntPtr systemComponentModelDesignComponentRenameEventHandlerInvoke
637641
public delegate void SystemComponentModelDesignIComponentChangeServiceRemoveComponentRenameDelegate(int thisHandle, int param0);
638642
public static SystemComponentModelDesignIComponentChangeServiceRemoveComponentRenameDelegate SystemComponentModelDesignIComponentChangeServiceRemoveComponentRename;
639643

644+
public delegate void SystemIOFileStreamWriteByteDelegate(int thisHandle, byte param0);
645+
public static SystemIOFileStreamWriteByteDelegate SystemIOFileStreamWriteByte;
646+
640647
public delegate void MyGameMonoBehavioursTestScriptAwakeDelegate(int thisHandle);
641648
public static MyGameMonoBehavioursTestScriptAwakeDelegate MyGameMonoBehavioursTestScriptAwake;
642649

@@ -897,6 +904,8 @@ static extern void Init(
897904
IntPtr boxPrimitiveType,
898905
IntPtr unboxPrimitiveType,
899906
IntPtr unityEngineTimePropertyGetDeltaTime,
907+
IntPtr boxFileMode,
908+
IntPtr unboxFileMode,
900909
IntPtr releaseSystemCollectionsGenericIComparerSystemInt32,
901910
IntPtr systemCollectionsGenericIComparerSystemInt32Constructor,
902911
IntPtr releaseSystemCollectionsGenericIComparerSystemString,
@@ -911,6 +920,8 @@ static extern void Init(
911920
IntPtr systemCollectionsQueueConstructor,
912921
IntPtr releaseSystemComponentModelDesignIComponentChangeService,
913922
IntPtr systemComponentModelDesignIComponentChangeServiceConstructor,
923+
IntPtr releaseSystemIOFileStream,
924+
IntPtr systemIOFileStreamConstructorSystemString_SystemIOFileMode,
914925
IntPtr boxBoolean,
915926
IntPtr unboxBoolean,
916927
IntPtr boxSByte,
@@ -1156,6 +1167,9 @@ IntPtr systemComponentModelDesignComponentRenameEventHandlerInvoke
11561167
[DllImport(Constants.PluginName)]
11571168
public static extern void SystemComponentModelDesignIComponentChangeServiceRemoveComponentRename(int thisHandle, int param0);
11581169

1170+
[DllImport(Constants.PluginName)]
1171+
public static extern void SystemIOFileStreamWriteByte(int thisHandle, int param0);
1172+
11591173
[DllImport(Constants.PluginName)]
11601174
public static extern void MyGameMonoBehavioursTestScriptAwake(int thisHandle);
11611175

@@ -1326,6 +1340,8 @@ IntPtr systemComponentModelDesignComponentRenameEventHandlerInvoke
13261340
delegate int BoxPrimitiveTypeDelegate(UnityEngine.PrimitiveType val);
13271341
delegate UnityEngine.PrimitiveType UnboxPrimitiveTypeDelegate(int valHandle);
13281342
delegate float UnityEngineTimePropertyGetDeltaTimeDelegate();
1343+
delegate int BoxFileModeDelegate(System.IO.FileMode val);
1344+
delegate System.IO.FileMode UnboxFileModeDelegate(int valHandle);
13291345
delegate void SystemCollectionsGenericIComparerSystemInt32ConstructorDelegate(int cppHandle, ref int handle);
13301346
delegate void ReleaseSystemCollectionsGenericIComparerSystemInt32Delegate(int handle);
13311347
delegate void SystemCollectionsGenericIComparerSystemStringConstructorDelegate(int cppHandle, ref int handle);
@@ -1340,6 +1356,8 @@ IntPtr systemComponentModelDesignComponentRenameEventHandlerInvoke
13401356
delegate void ReleaseSystemCollectionsQueueDelegate(int handle);
13411357
delegate void SystemComponentModelDesignIComponentChangeServiceConstructorDelegate(int cppHandle, ref int handle);
13421358
delegate void ReleaseSystemComponentModelDesignIComponentChangeServiceDelegate(int handle);
1359+
delegate void SystemIOFileStreamConstructorSystemString_SystemIOFileModeDelegate(int cppHandle, ref int handle, int pathHandle, System.IO.FileMode mode);
1360+
delegate void ReleaseSystemIOFileStreamDelegate(int handle);
13431361
delegate int BoxBooleanDelegate(bool val);
13441362
delegate bool UnboxBooleanDelegate(int valHandle);
13451363
delegate int BoxSByteDelegate(sbyte val);
@@ -1527,6 +1545,7 @@ public static void Open(
15271545
SystemComponentModelDesignIComponentChangeServiceRemoveComponentRemoving = GetDelegate<SystemComponentModelDesignIComponentChangeServiceRemoveComponentRemovingDelegate>(libraryHandle, "SystemComponentModelDesignIComponentChangeServiceRemoveComponentRemoving");
15281546
SystemComponentModelDesignIComponentChangeServiceAddComponentRename = GetDelegate<SystemComponentModelDesignIComponentChangeServiceAddComponentRenameDelegate>(libraryHandle, "SystemComponentModelDesignIComponentChangeServiceAddComponentRename");
15291547
SystemComponentModelDesignIComponentChangeServiceRemoveComponentRename = GetDelegate<SystemComponentModelDesignIComponentChangeServiceRemoveComponentRenameDelegate>(libraryHandle, "SystemComponentModelDesignIComponentChangeServiceRemoveComponentRename");
1548+
SystemIOFileStreamWriteByte = GetDelegate<SystemIOFileStreamWriteByteDelegate>(libraryHandle, "SystemIOFileStreamWriteByte");
15301549
MyGameMonoBehavioursTestScriptAwake = GetDelegate<MyGameMonoBehavioursTestScriptAwakeDelegate>(libraryHandle, "MyGameMonoBehavioursTestScriptAwake");
15311550
MyGameMonoBehavioursTestScriptOnAnimatorIK = GetDelegate<MyGameMonoBehavioursTestScriptOnAnimatorIKDelegate>(libraryHandle, "MyGameMonoBehavioursTestScriptOnAnimatorIK");
15321551
MyGameMonoBehavioursTestScriptOnCollisionEnter = GetDelegate<MyGameMonoBehavioursTestScriptOnCollisionEnterDelegate>(libraryHandle, "MyGameMonoBehavioursTestScriptOnCollisionEnter");
@@ -1663,6 +1682,8 @@ public static void Open(
16631682
Marshal.GetFunctionPointerForDelegate(new BoxPrimitiveTypeDelegate(BoxPrimitiveType)),
16641683
Marshal.GetFunctionPointerForDelegate(new UnboxPrimitiveTypeDelegate(UnboxPrimitiveType)),
16651684
Marshal.GetFunctionPointerForDelegate(new UnityEngineTimePropertyGetDeltaTimeDelegate(UnityEngineTimePropertyGetDeltaTime)),
1685+
Marshal.GetFunctionPointerForDelegate(new BoxFileModeDelegate(BoxFileMode)),
1686+
Marshal.GetFunctionPointerForDelegate(new UnboxFileModeDelegate(UnboxFileMode)),
16661687
Marshal.GetFunctionPointerForDelegate(new ReleaseSystemCollectionsGenericIComparerSystemInt32Delegate(ReleaseSystemCollectionsGenericIComparerSystemInt32)),
16671688
Marshal.GetFunctionPointerForDelegate(new SystemCollectionsGenericIComparerSystemInt32ConstructorDelegate(SystemCollectionsGenericIComparerSystemInt32Constructor)),
16681689
Marshal.GetFunctionPointerForDelegate(new ReleaseSystemCollectionsGenericIComparerSystemStringDelegate(ReleaseSystemCollectionsGenericIComparerSystemString)),
@@ -1677,6 +1698,8 @@ public static void Open(
16771698
Marshal.GetFunctionPointerForDelegate(new SystemCollectionsQueueConstructorDelegate(SystemCollectionsQueueConstructor)),
16781699
Marshal.GetFunctionPointerForDelegate(new ReleaseSystemComponentModelDesignIComponentChangeServiceDelegate(ReleaseSystemComponentModelDesignIComponentChangeService)),
16791700
Marshal.GetFunctionPointerForDelegate(new SystemComponentModelDesignIComponentChangeServiceConstructorDelegate(SystemComponentModelDesignIComponentChangeServiceConstructor)),
1701+
Marshal.GetFunctionPointerForDelegate(new ReleaseSystemIOFileStreamDelegate(ReleaseSystemIOFileStream)),
1702+
Marshal.GetFunctionPointerForDelegate(new SystemIOFileStreamConstructorSystemString_SystemIOFileModeDelegate(SystemIOFileStreamConstructorSystemString_SystemIOFileMode)),
16801703
Marshal.GetFunctionPointerForDelegate(new BoxBooleanDelegate(BoxBoolean)),
16811704
Marshal.GetFunctionPointerForDelegate(new UnboxBooleanDelegate(UnboxBoolean)),
16821705
Marshal.GetFunctionPointerForDelegate(new BoxSByteDelegate(BoxSByte)),
@@ -1848,6 +1871,7 @@ class SystemCollectionsGenericIComparerSystemInt32 : System.Collections.Generic.
18481871
public int CppHandle;
18491872

18501873
public SystemCollectionsGenericIComparerSystemInt32(int cppHandle)
1874+
: base()
18511875
{
18521876
CppHandle = cppHandle;
18531877
}
@@ -1876,6 +1900,7 @@ class SystemCollectionsGenericIComparerSystemString : System.Collections.Generic
18761900
public int CppHandle;
18771901

18781902
public SystemCollectionsGenericIComparerSystemString(int cppHandle)
1903+
: base()
18791904
{
18801905
CppHandle = cppHandle;
18811906
}
@@ -1906,6 +1931,7 @@ class SystemStringComparer : System.StringComparer
19061931
public int CppHandle;
19071932

19081933
public SystemStringComparer(int cppHandle)
1934+
: base()
19091935
{
19101936
CppHandle = cppHandle;
19111937
}
@@ -1973,6 +1999,7 @@ class SystemCollectionsICollection : System.Collections.ICollection
19731999
public int CppHandle;
19742000

19752001
public SystemCollectionsICollection(int cppHandle)
2002+
: base()
19762003
{
19772004
CppHandle = cppHandle;
19782005
}
@@ -2077,6 +2104,7 @@ class SystemCollectionsIList : System.Collections.IList
20772104
public int CppHandle;
20782105

20792106
public SystemCollectionsIList(int cppHandle)
2107+
: base()
20802108
{
20812109
CppHandle = cppHandle;
20822110
}
@@ -2372,6 +2400,7 @@ class SystemCollectionsQueue : System.Collections.Queue
23722400
public int CppHandle;
23732401

23742402
public SystemCollectionsQueue(int cppHandle)
2403+
: base()
23752404
{
23762405
CppHandle = cppHandle;
23772406
}
@@ -2403,6 +2432,7 @@ class SystemComponentModelDesignIComponentChangeService : System.ComponentModel.
24032432
public int CppHandle;
24042433

24052434
public SystemComponentModelDesignIComponentChangeService(int cppHandle)
2435+
: base()
24062436
{
24072437
CppHandle = cppHandle;
24082438
}
@@ -2683,6 +2713,33 @@ public event System.ComponentModel.Design.ComponentRenameEventHandler ComponentR
26832713

26842714
}
26852715

2716+
class SystemIOFileStream : System.IO.FileStream
2717+
{
2718+
public int CppHandle;
2719+
2720+
public SystemIOFileStream(int cppHandle, string path, System.IO.FileMode mode)
2721+
: base(path, mode)
2722+
{
2723+
CppHandle = cppHandle;
2724+
}
2725+
2726+
public override void WriteByte(byte value)
2727+
{
2728+
if (CppHandle != 0)
2729+
{
2730+
int thisHandle = CppHandle;
2731+
NativeScript.Bindings.SystemIOFileStreamWriteByte(thisHandle, value);
2732+
if (NativeScript.Bindings.UnhandledCppException != null)
2733+
{
2734+
Exception ex = NativeScript.Bindings.UnhandledCppException;
2735+
NativeScript.Bindings.UnhandledCppException = null;
2736+
throw ex;
2737+
}
2738+
}
2739+
}
2740+
2741+
}
2742+
26862743
class SystemAction
26872744
{
26882745
public int CppHandle;
@@ -5331,6 +5388,51 @@ static float UnityEngineTimePropertyGetDeltaTime()
53315388
}
53325389
}
53335390

5391+
[MonoPInvokeCallback(typeof(BoxFileModeDelegate))]
5392+
static int BoxFileMode(System.IO.FileMode val)
5393+
{
5394+
try
5395+
{
5396+
var returnValue = NativeScript.Bindings.ObjectStore.Store((object)val);
5397+
return returnValue;
5398+
}
5399+
catch (System.NullReferenceException ex)
5400+
{
5401+
UnityEngine.Debug.LogException(ex);
5402+
NativeScript.Bindings.SetCsharpExceptionSystemNullReferenceException(NativeScript.Bindings.ObjectStore.Store(ex));
5403+
return default(int);
5404+
}
5405+
catch (System.Exception ex)
5406+
{
5407+
UnityEngine.Debug.LogException(ex);
5408+
NativeScript.Bindings.SetCsharpException(NativeScript.Bindings.ObjectStore.Store(ex));
5409+
return default(int);
5410+
}
5411+
}
5412+
5413+
[MonoPInvokeCallback(typeof(UnboxFileModeDelegate))]
5414+
static System.IO.FileMode UnboxFileMode(int valHandle)
5415+
{
5416+
try
5417+
{
5418+
var val = NativeScript.Bindings.ObjectStore.Get(valHandle);
5419+
var returnValue = (System.IO.FileMode)val;
5420+
return returnValue;
5421+
}
5422+
catch (System.NullReferenceException ex)
5423+
{
5424+
UnityEngine.Debug.LogException(ex);
5425+
NativeScript.Bindings.SetCsharpExceptionSystemNullReferenceException(NativeScript.Bindings.ObjectStore.Store(ex));
5426+
return default(System.IO.FileMode);
5427+
}
5428+
catch (System.Exception ex)
5429+
{
5430+
UnityEngine.Debug.LogException(ex);
5431+
NativeScript.Bindings.SetCsharpException(NativeScript.Bindings.ObjectStore.Store(ex));
5432+
return default(System.IO.FileMode);
5433+
}
5434+
}
5435+
53345436
[MonoPInvokeCallback(typeof(SystemCollectionsGenericIComparerSystemInt32ConstructorDelegate))]
53355437
static void SystemCollectionsGenericIComparerSystemInt32Constructor(int cppHandle, ref int handle)
53365438
{
@@ -5604,6 +5706,46 @@ static void ReleaseSystemComponentModelDesignIComponentChangeService(int handle)
56045706
}
56055707
}
56065708

5709+
[MonoPInvokeCallback(typeof(SystemIOFileStreamConstructorSystemString_SystemIOFileModeDelegate))]
5710+
static void SystemIOFileStreamConstructorSystemString_SystemIOFileMode(int cppHandle, ref int handle, int pathHandle, System.IO.FileMode mode)
5711+
{
5712+
try
5713+
{
5714+
var path = (string)NativeScript.Bindings.ObjectStore.Get(pathHandle);
5715+
var thiz = new SystemIOFileStream(cppHandle, path, mode);
5716+
handle = NativeScript.Bindings.ObjectStore.Store(thiz);
5717+
}
5718+
catch (System.NullReferenceException ex)
5719+
{
5720+
UnityEngine.Debug.LogException(ex);
5721+
NativeScript.Bindings.SetCsharpExceptionSystemNullReferenceException(NativeScript.Bindings.ObjectStore.Store(ex));
5722+
}
5723+
catch (System.Exception ex)
5724+
{
5725+
UnityEngine.Debug.LogException(ex);
5726+
NativeScript.Bindings.SetCsharpException(NativeScript.Bindings.ObjectStore.Store(ex));
5727+
}
5728+
}
5729+
5730+
[MonoPInvokeCallback(typeof(ReleaseSystemIOFileStreamDelegate))]
5731+
static void ReleaseSystemIOFileStream(int handle)
5732+
{
5733+
try
5734+
{
5735+
NativeScript.Bindings.ObjectStore.Remove(handle);
5736+
}
5737+
catch (System.NullReferenceException ex)
5738+
{
5739+
UnityEngine.Debug.LogException(ex);
5740+
NativeScript.Bindings.SetCsharpExceptionSystemNullReferenceException(NativeScript.Bindings.ObjectStore.Store(ex));
5741+
}
5742+
catch (System.Exception ex)
5743+
{
5744+
UnityEngine.Debug.LogException(ex);
5745+
NativeScript.Bindings.SetCsharpException(NativeScript.Bindings.ObjectStore.Store(ex));
5746+
}
5747+
}
5748+
56075749
[MonoPInvokeCallback(typeof(BoxBooleanDelegate))]
56085750
static int BoxBoolean(bool val)
56095751
{

0 commit comments

Comments
 (0)