(basepath, c_header_path, out_path, info, ast, state, docs)
| 206 | |
| 207 | |
| 208 | def gen_csharp(basepath, c_header_path, out_path, info, ast, state, docs): |
| 209 | _reset_globals() |
| 210 | |
| 211 | l('// Generated, do not edit!') |
| 212 | l('// Generated with cwd=%s and cmd=%s\n' % (os.getcwd(), ' '.join(sys.argv))) |
| 213 | |
| 214 | license = info.get('license', 'License: Defold License (https://github.com/defold/defold/blob/dev/LICENSE.txt)') |
| 215 | license = license.split('\n') |
| 216 | license = '\n'.join(['// ' + line for line in license]) |
| 217 | |
| 218 | l('%s\n' % license) |
| 219 | |
| 220 | namespace = info.get('namespace', None) |
| 221 | classname = info.get('class', None) |
| 222 | dllimport = info.get('dllimport', None) |
| 223 | using = info.get('using', []) |
| 224 | using_static= info.get('using_static', []) |
| 225 | |
| 226 | if not namespace: |
| 227 | raise Exception("C# file has no 'namespace' defined!") |
| 228 | if not classname: |
| 229 | raise Exception("C# file has no 'classname' defined!") |
| 230 | if not dllimport: |
| 231 | raise Exception("C# file has no 'dllimport' defined!") |
| 232 | |
| 233 | indent = 1 |
| 234 | spaces = ' ' * indent |
| 235 | spaces1 = ' ' * (indent+1) |
| 236 | |
| 237 | # Dock header |
| 238 | api_name = docs.get('name', None) |
| 239 | if api_name is None: |
| 240 | api_name = os.path.splitext(os.path.basename(out_path))[0].capitalize() |
| 241 | |
| 242 | language = 'C#' |
| 243 | brief = docs.get('brief', '') |
| 244 | description = docs.get('desc', '') |
| 245 | description = description.replace('\n', '\n * ') |
| 246 | |
| 247 | if api_name is None: |
| 248 | api_name = os.path.splitext(os.path.basename(out_path))[0].capitalize() |
| 249 | |
| 250 | namespace = info.get('namespace', None) |
| 251 | |
| 252 | source_path = os.path.relpath(out_path, basepath) |
| 253 | |
| 254 | doc_header = gen_doc_header(api_name, brief, description, language, namespace, source_path) |
| 255 | l(doc_header) |
| 256 | |
| 257 | # C# begin |
| 258 | l(f'using System.Runtime.InteropServices;') |
| 259 | l(f'using System.Reflection.Emit;') |
| 260 | |
| 261 | l(f'') |
| 262 | for u in using: |
| 263 | l(f'using {u};') |
| 264 | for u in using_static: |
| 265 | l(f'using static {u};') |
nothing calls this directly
no test coverage detected