Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make types in the C# API partial #1675

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions codegen/api_shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,8 @@ def outputstructfields(struct, data):
print('return new string(new char[] {')
for i in range(0, size-1):
print('(char)' + enumvalue['fieldname'] + str(i) + ',')
print('(char)' + enumvalue['fieldname'] + str(size-1) + '}).TrimEnd(\'\\0\');')
print('(char)' + enumvalue['fieldname'] + str(size-1))
print('}).TrimEnd(\'\\0\');')
print('}')
print('}')
else:
Expand All @@ -364,7 +365,7 @@ def outputstructs(namespace, data):
basename = getclasswithoutnamespace(key)
break

print('[StructLayout(LayoutKind.Sequential)] public struct '+basename+'\n{')
print('[StructLayout(LayoutKind.Sequential)] public partial struct '+basename+'\n{')
outputstructfields(struct, data)

if (basename == 'HmdMatrix34_t'):
Expand Down Expand Up @@ -416,7 +417,7 @@ def outputstructs(namespace, data):
(basename == 'RenderModel_TextureMap_t') or
(basename == 'VREvent_t')):
print('// This structure is for backwards binary compatibility on Linux and OSX only')
print('[StructLayout(LayoutKind.Sequential, Pack = 4)] public struct '+basename+'_Packed\n{')
print('[StructLayout(LayoutKind.Sequential, Pack = 4)] public partial struct '+basename+'_Packed\n{')
outputstructfields(struct, data)
print('\tpublic '+basename+'_Packed('+basename+' unpacked)');
print('\t{')
Expand Down Expand Up @@ -481,7 +482,7 @@ def outputinterfaces(namespace, data):
print("\t}\n");

print("\t[StructLayout(LayoutKind.Sequential)]")
print("\tpublic struct " + classname + "\n\t{")
print("\tpublic partial struct " + classname + "\n\t{")
lastclass = classname


Expand Down Expand Up @@ -727,7 +728,7 @@ def isparamptr(paramname, paramlist):

def outputclasses(namespace, data):

print("""public class Utils
print("""public partial class Utils
{
public static IntPtr ToUtf8(string managedString)
{
Expand Down Expand Up @@ -783,7 +784,7 @@ def outputclasses(namespace, data):
print("}\n\n");
classname = 'C' + interfacename[1:]
classshort = interfacename[1:]
print("public class " + classname+"\n{")
print("public partial class " + classname+"\n{")
print(interfacename+" FnTable;")
print("internal " + classname + "(IntPtr pInterface)")
print("{")
Expand Down Expand Up @@ -915,7 +916,7 @@ def outputclasses(namespace, data):
print('[UnmanagedFunctionPointer(CallingConvention.StdCall)]')
print('internal delegate '+returntype+' _'+methodname+'Packed('+','.join(packedlist)+');')
print('[StructLayout(LayoutKind.Explicit)]')
print('struct '+methodname+'Union\n{')
print('partial struct '+methodname+'Union\n{')
print('\t[FieldOffset(0)]\n\tpublic '+interfacename+'._'+methodname+' p'+methodname+';')
print('\t[FieldOffset(0)]\n\tpublic _'+methodname+'Packed p'+methodname+'Packed;\n}')

Expand Down
10 changes: 5 additions & 5 deletions codegen/openvr_interop.cs.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
print("}\n\n");

# Output the OpenVRInterop class
print('public class OpenVRInterop\n{')
print('public partial class OpenVRInterop\n{')
print('[DllImportAttribute("openvr_api", EntryPoint = "VR_InitInternal", CallingConvention = CallingConvention.Cdecl)]')
print('internal static extern uint InitInternal(ref EVRInitError peError, EVRApplicationType eApplicationType);')
print('[DllImportAttribute("openvr_api", EntryPoint = "VR_InitInternal2", CallingConvention = CallingConvention.Cdecl)]')
Expand Down Expand Up @@ -71,7 +71,7 @@
api_shared.outputenums('vr', data)

print("""
[StructLayout(LayoutKind.Explicit)] public struct VREvent_Data_t
[StructLayout(LayoutKind.Explicit)] public partial struct VREvent_Data_t
{
[FieldOffset(0)] public VREvent_Reserved_t reserved;
[FieldOffset(0)] public VREvent_Controller_t controller;
Expand Down Expand Up @@ -106,7 +106,7 @@
""")

print("""
[StructLayout(LayoutKind.Explicit)] public struct VROverlayIntersectionMaskPrimitive_Data_t
[StructLayout(LayoutKind.Explicit)] public partial struct VROverlayIntersectionMaskPrimitive_Data_t
{
[FieldOffset(0)] public IntersectionMaskRectangle_t m_Rectangle;
[FieldOffset(0)] public IntersectionMaskCircle_t m_Circle;
Expand All @@ -117,7 +117,7 @@


# Output the OpenVR class
print('\npublic class OpenVR\n{')
print('\npublic partial class OpenVR\n{')
print("""
public static uint InitInternal(ref EVRInitError peError, EVRApplicationType eApplicationType)
{
Expand Down Expand Up @@ -233,7 +233,7 @@

const string FnTable_Prefix = "FnTable:";

class COpenVRContext
partial class COpenVRContext
{
public COpenVRContext() { Clear(); }

Expand Down
Loading