MCPcopy Create free account
hub / github.com/defold/defold / gen_cs_struct

Function gen_cs_struct

scripts/dmsdk/gen_csharp.py:170–204  ·  view source on GitHub ↗
(decl, rename_patterns, opaque, indent)

Source from the content-addressed store, hash-verified

168 return 'public static extern %s %s(%s)' % (ret_type, decl['name'], ', '.join(args))
169
170def gen_cs_struct(decl, rename_patterns, opaque, indent):
171 #pprint.pprint(decl, sys.stdout)
172
173 name = rename_symbols(rename_patterns, decl['name'])
174 while name.endswith('*'):
175 name = name[:-1]
176
177 spaces = get_indent(indent)
178 spaces1 = get_indent(indent+1)
179 s = ''
180 s += f'{spaces}[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack=1)]\n'
181 s += f'{spaces}public struct {name}\n'
182 s += f'{spaces}{{\n'
183
184 if opaque:
185 s += f'{spaces} // opaque struct\n'
186 else:
187 for member in decl['inner']:
188 n = member['name']
189 if n.startswith('m_'):
190 n = n[2:]
191 n = rename_symbols(rename_patterns, n)
192 t = rename_symbols(rename_patterns, member['type']['qualType'])
193
194 if t.startswith('//'):
195 ot = member['type']['qualType']
196 print(f"CS: Warning: exiting struct {name}, as member {ot} {n} isn't supported yet")
197 break # if we skip one, we can't guarantuee the order/layout
198
199 # TODO: Find out the layout!
200 s += f'{spaces1}public {t} {n};\n'
201
202
203 s += f'{spaces}}}'
204 return s
205
206
207

Callers 1

gen_csharpFunction · 0.85

Calls 3

rename_symbolsFunction · 0.70
get_indentFunction · 0.70
printFunction · 0.50

Tested by

no test coverage detected