-
Notifications
You must be signed in to change notification settings - Fork 3
/
generate.js
660 lines (593 loc) · 20.1 KB
/
generate.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
const _ = require("lodash");
const changeCase = require('change-case');
const nunjucks = require("nunjucks");
const fs = require("fs");
const program = require("commander");
nunjucks.configure({
autoescape: false
});
const definitions = JSON.parse(fs.readFileSync("data/definitions.json", "utf-8"));
const structsAndEnums = JSON.parse(fs.readFileSync("data/structs_and_enums.json", "utf-8"));
const typedefs = JSON.parse(fs.readFileSync("data/typedefs_dict.json", "utf-8"));
const blacklistedTypedefs = {
// some C++ artifacts from templates
'const_iterator': true,
'iterator': true,
'value_type': true,
}
const blacklistedStructs = {
'Pair': true, // has a union inside, let's implement it manually
'ImVector': true, // template type, let's implement it manually
}
const typedefsSorted = _.keys(typedefs).sort();
const typeMap = {
'bool': 'bool',
'char': 'c_char',
'double': 'c_double',
'float': 'c_float',
'int': 'c_int',
'int64_t': 'i64',
'Pair': 'Pair',
'short': 'c_short',
'signed int': 'c_int', // iirc, "int == signed int" in C, "char != signed char" though
'uint64_t': 'u64',
'unsigned char': 'c_uchar',
'unsigned int': 'c_uint',
'unsigned short': 'c_ushort',
'unsigned_char': 'c_uchar',
'void': 'c_void',
'bool(*)(void* data,int idx,const char** out_text)': 'extern "C" fn(data: *mut c_void, idx: c_int, out_text: *mut *const c_char) -> bool',
'const char*(*)(void* user_data)': 'Option<extern "C" fn(user_data: *mut c_void) -> *const c_char>',
'float(*)(void* data,int idx)': 'extern "C" fn(data: *mut c_void, idx: c_int) -> c_float',
'void(*)(int x,int y)': 'Option<extern "C" fn(x: c_int, y: c_int)>',
'void(*)(void* ptr,void* user_data)': 'Option<extern "C" fn(ptr: *mut c_void, user_data: *mut c_void)>',
'void(*)(void* user_data,const char* text)': 'Option<extern "C" fn(user_data: *mut c_void, text: *const c_char)>',
'void*(*)(size_t sz,void* user_data)': 'Option<extern "C" fn(sz: usize, user_data: *mut c_void) -> *mut c_void>',
'ImColor_Simple': 'ImColor_Simple',
'ImDrawCallback': 'ImDrawCallback',
'ImDrawListSharedData': 'ImDrawListSharedData',
'ImFontPtr': 'ImFontPtr',
'ImGuiContext': 'ImGuiContext',
'ImGuiInputTextCallback': 'ImGuiInputTextCallback',
'ImGuiSizeCallback': 'ImGuiSizeCallback',
'ImVec2_Simple': 'ImVec2_Simple',
'ImVec4_Simple': 'ImVec4_Simple',
'size_t': 'size_t',
}
const snakeCaseManualCases = {
'ColorConvertRGBtoHSV': 'color_convert_rgb_to_hsv',
'ColorConvertHSVtoRGB': 'color_convert_hsv_to_rgb',
}
function snakeCase(s) {
const v = snakeCaseManualCases[s];
return v || changeCase.snakeCase(s);
}
function addKnownTypes() {
const alreadyAdded = [];
const addFrom = (collection, name) => {
for (const v of collection) {
if (typeMap[v]) {
alreadyAdded.push({key: v, collection: name});
} else {
typeMap[v] = v;
}
}
}
addFrom(allEnumNames(), 'Enum');
addFrom(allStructNames(), 'Struct');
addFrom(allTypedefNames(), 'Typedef');
if (alreadyAdded.length > 0) {
throw new Error(`already added: ${_.join(_.map(alreadyAdded, JSON.stringify), ', ')}`);
}
}
addKnownTypes();
function extractArity(name) {
const re = /\[([^\]]+)\]/g;
const m = re.exec(name);
if (m) {
const mm = /([^_]+)_(.+)/.exec(m[1]);
if (mm) {
return `${mm[1]}::${mm[2]} as usize`;
}
return m[1];
}
return '';
}
function stripArity(name) {
return name.replace(/\[[^\]]+\]/g, '')
}
function mapType(t, opts) {
const prefix = (opts && opts.prefix) || '';
const arity = (opts && opts.arity) || '';
// some manual overrides
if (t === 'const char* const[]') {
return '*const *const c_char';
}
if (t.indexOf("(*)") === -1) {
// we mess with types, but only if they are not a function pointer, those are special
if (_.startsWith(t, 'const ') && _.endsWith(t, '*')) {
// it's not exactly a C syntax parser here, but for given cases it works,
// converts "const Foo*" to "*const Foo"
const nt = t.substr(0, t.length-1).substr('const '.length);
return mapType(nt, { ...opts, prefix: `*const ${prefix}` });
} else if (_.startsWith(t, 'const ')) {
const nt = t.substr('const '.length);
return mapType(nt, opts);
}
if (_.endsWith(t, '*') || _.endsWith(t, '&')) {
// it's not exactly a C syntax parser here, but for given cases it works,
// converts "Foo*" to "*mut Foo"
return mapType(t.substr(0, t.length-1), { ...opts, prefix: `*mut ${prefix}` });
}
if (_.endsWith(t, ']')) {
// arity in a type, happens in functions, in that case we need to convert it to a pointer to an array
// C array types are just pointers
const arity = extractArity(t);
const nt = stripArity(t) + '*';
return mapType(nt, { ...opts, arity });
}
if (_.startsWith(t, "ImVector_")) {
return `${prefix}ImVector<${mapType(t.substr("ImVector_".length))}>`;
}
}
const result = typeMap[t];
if (!result) {
throw new Error(`unknown type: ${prefix}${t}`);
}
if (arity) {
return `${prefix}[${result}; ${arity}]`;
} else {
return `${prefix}${result}`;
}
}
//=========================================================================================
// HEADER AND MANUALLY IMPLEMENTED THINGS
//=========================================================================================
function generateHeader() {
console.log(`
use bitflags::bitflags;
use std::os::raw::{c_char, c_double, c_float, c_int, c_short, c_uchar, c_uint, c_ushort, c_void};
use libc::size_t;
use std::slice;
#[repr(C)]
pub struct ImVector<T> {
size: c_int,
capacity: c_int,
data: *mut T,
}
impl<T> ImVector<T> {
pub unsafe fn as_slice(&self) -> &[T] {
slice::from_raw_parts(self.data, self.size as usize)
}
}
#[repr(C)]
pub struct Pair {
pub key: ImGuiID,
pub value: PairValue,
}
#[repr(C)]
pub union PairValue {
pub val_i: c_int,
pub val_f: c_float,
pub val_p: *mut c_void,
}
// opaque types
pub enum ImDrawListSharedData {}
pub enum ImGuiContext {}
pub type ImFontPtr = *mut ImFont;
pub type ImDrawCallback = Option<extern "C" fn(parent_list: *const ImDrawList, cmd: *const ImDrawCmd)>;
pub type ImGuiInputTextCallback = Option<extern "C" fn(data: *mut ImGuiInputTextCallbackData) -> c_int>;
pub type ImGuiSizeCallback = Option<extern "C" fn(data: *mut ImGuiSizeCallbackData)>;
`.substr(1));
}
//=========================================================================================
// TYPEDEFS
//=========================================================================================
function allTypedefNames() {
return _.filter(typedefsSorted, typedef => !isTypedefBlacklisted(typedef, typedefs[typedef]));
}
function isTypedefBlacklisted(typedef, val) {
if (_.startsWith(val, "struct ")) { // not interested in struct typedefs
return true;
}
if (val.indexOf("(*)") !== -1) { // function pointer typedefs are done manually
return true;
}
if (blacklistedTypedefs[typedef]) {
return true;
}
if (structsAndEnums.enums[typedef+"_"]) { // not interested in enums either
return true;
}
return false;
}
function generateTypedefs() {
for (const typedef of typedefsSorted) {
const val = typedefs[typedef];
if (isTypedefBlacklisted(typedef, val)) {
continue;
}
console.log(`pub type ${typedef} = ${mapType(val)};`);
}
}
//=========================================================================================
// ENUMS
//=========================================================================================
const bitflagsTemplate = `
bitflags! {
#[repr(C)]
pub struct {{ name }}: {{ type }} {
{%- for f in fields %}
const {{ f.name }} = {{ f.value }};
{%- endfor %}
}
}
`;
const enumTemplate = `
#[repr(C)]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum {{ name }} {
{%- for f in fields %}
{{ f.name }} = {{ f.value }},
{%- endfor %}
}
`;
function isBitFlags(fields) {
return _.some(fields, f => _.isString(f.value) && f.value.indexOf("<<") !== -1);
}
function processBitFlagsValue(v, nameRaw) {
if (!_.isString(v)) {
return v;
}
const re = new RegExp(nameRaw+`([A-Za-z0-9_]+)`, 'g');
return v.replace(re, (m, name) => {
return `Self::${name}.bits`;
});
}
function allEnumNames() {
return _.map(_.keys(structsAndEnums.enums), e => _.trimEnd(e, '_'));
}
function generateEnums() {
for (const nameRaw of _.keys(structsAndEnums.enums)) {
const fields = structsAndEnums.enums[nameRaw];
const name = _.trimEnd(nameRaw, '_');
const data = {
name,
type: mapType(typedefs[name]),
fields: _.map(fields, f => ({
...f,
name: _.startsWith(f.name, nameRaw) ? f.name.substr(nameRaw.length) : f.name,
value: processBitFlagsValue(f.value, nameRaw),
})),
};
if (isBitFlags(fields)) {
const result = nunjucks.renderString(bitflagsTemplate, data);
console.log(result);
} else {
const valsMap = {};
data.fields = _.filter(data.fields, f => {
if (valsMap[f.calc_value]) {
return false;
} else {
valsMap[f.calc_value] = true;
return true;
}
});
const result = nunjucks.renderString(enumTemplate, data);
console.log(result);
}
}
}
//=========================================================================================
// STRUCTS
//=========================================================================================
const structTemplate = `
#[repr(C)]
{%- if simple %}
#[derive(Copy, Clone)]{% endif %}
pub struct {{ name }} {
{%- for f in fields %}
pub {{ f.name }}: {{ f.type }},
{%- endfor %}
}
`;
const simpleStructs = {
'ImVec2': true,
'ImVec4': true,
}
function allStructNames() {
return _.filter(_.keys(structsAndEnums.structs), s => !blacklistedStructs[s]);
}
function generateStructs() {
for (const name of _.keys(structsAndEnums.structs)) {
if (blacklistedStructs[name]) {
continue;
}
const fields = structsAndEnums.structs[name];
const result = nunjucks.renderString(structTemplate, {
name,
simple: !!simpleStructs[name],
fields: _.map(fields, f => ({
type: mapType(f.type, { arity: extractArity(f.name) }),
name: snakeCase(stripArity(f.name)),
})),
});
console.log(result);
}
}
//=========================================================================================
// FUNCTIONS
//=========================================================================================
const funcTemplate = `
pub fn {{name}}(
{%- for a in args -%}
{%- if not loop.first %}, {% endif %}{{ a.name }}{% if a.type %}: {% endif %}{{ a.type -}}
{% endfor -%}
)
{%- if ret %} -> {{ ret }}{% endif %};
`;
const safeArgNameMap = {
'type': '_type',
'ref': '_ref',
'self': '_self',
'in': '_in',
}
function safeArgName(v) {
return safeArgNameMap[v] || v;
}
function generateFuncs() {
console.log(`extern "C" {`);
for (const name of _.keys(definitions)) {
const funcs = definitions[name];
for (const func of funcs) {
if (func.nonUDT) { // rust works just fine here
continue;
}
if (_.some(func.argsT, a => a.type === 'va_list')) {
// skip va_list variants, we're fine with "..." notation, in most cases it's about string formatting
// and we'll just use ("%s", str)
continue;
}
const name = func.ov_cimguiname || func.cimguiname;
const ret = func.ret && func.ret !== 'void' ? mapType(func.ret) : undefined;
const args = _.map(func.argsT, a => ({
name: safeArgName(a.name),
type: a.name === '...' ? undefined : mapType(a.type),
}));
const result = nunjucks.renderString(funcTemplate, {
name,
ret,
args,
});
console.log(_.trim(result));
}
}
console.log(`} // extern "C"`);
}
//=========================================================================================
// SAFE WRAPPERS
//=========================================================================================
const blacklistedSafeFuncs = {
'igCreateContext': true, // calls to it are made by ImGui object
'igDestroyContext': true, // calls to it are made by ImGui object
'igMemAlloc': true, // raw memory
'igMemFree': true, // raw memory
'igSetAllocatorFunctions': true, // use unsafe interface if you want to override those
'igSetCurrentContext': true, // currently we assume only one context per lib usage
'igTextUnformatted': true, // has "end" pointer, TODO: we could make &str interface for it
}
const safeArgTypeConv = {
'*const c_char': v => `${v}.as_ptr()`,
};
const safeRetTypeConv = {
'*const c_char': v => `CStr::from_ptr(${v}).to_string_lossy().into_owned()`,
};
const safeTypeMap = {
'*const ImVec2': (g) => `&'${g.next()} ImVec2`,
'*const c_char': (g) => `&'${g.next()} CStr`,
'*const c_float': (g) => `&'${g.next()} f32`,
'*mut [c_float; 2]': (g) => `&'${g.next()} mut [f32; 2]`,
'*mut [c_float; 3]': (g) => `&'${g.next()} mut [f32; 3]`,
'*mut [c_float; 4]': (g) => `&'${g.next()} mut [f32; 4]`,
'*mut [c_int; 2]': (g) => `&'${g.next()} mut [i32; 2]`,
'*mut [c_int; 3]': (g) => `&'${g.next()} mut [i32; 3]`,
'*mut [c_int; 4]': (g) => `&'${g.next()} mut [i32; 4]`,
'*mut bool': (g) => `&'${g.next()} mut bool`,
'*mut c_double': (g) => `&'${g.next()} mut f64`,
'*mut c_float': (g) => `&'${g.next()} mut f32`,
'*mut c_int': (g) => `&'${g.next()} mut i32`,
'*mut c_uint': (g) => `&'${g.next()} mut u32`,
'*mut size_t': (g) => `&'${g.next()} mut usize`,
'ImGuiCol': () => 'ImGuiCol',
'ImGuiColorEditFlags': () => 'ImGuiColorEditFlags',
'ImGuiComboFlags': () => 'ImGuiComboFlags',
'ImGuiCond': () => 'ImGuiCond',
'ImGuiDataType': () => 'ImGuiDataType',
'ImGuiDir': () => 'ImGuiDir',
'ImGuiDragDropFlags': () => 'ImGuiDragDropFlags',
'ImGuiFocusedFlags': () => 'ImGuiFocusedFlags',
'ImGuiHoveredFlags': () => 'ImGuiHoveredFlags',
'ImGuiID': () => 'ImGuiID',
'ImGuiInputTextCallback': () => 'ImGuiInputTextCallback',
'ImGuiInputTextFlags': () => 'ImGuiInputTextFlags',
'ImGuiKey': () => 'ImGuiKey',
'ImGuiMouseCursor': () => 'ImGuiMouseCursor',
'ImGuiSelectableFlags': () => 'ImGuiSelectableFlags',
'ImGuiSizeCallback': () => 'ImGuiSizeCallback',
'ImGuiStyleVar': () => 'ImGuiStyleVar',
'ImGuiTreeNodeFlags': () => 'ImGuiTreeNodeFlags',
'ImGuiWindowFlags': () => 'ImGuiWindowFlags',
'ImTextureID': () => 'ImTextureID',
'ImU32': () => 'u32',
'ImVec2': () => 'ImVec2',
'ImVec4': () => 'ImVec4',
'bool': () => 'bool',
'c_double': () => 'f64',
'c_float': () => 'f32',
'c_int': () => 'i32',
'c_uint': () => 'u32',
'size_t': () => 'usize',
};
const safeRetTypeMap = {
...safeTypeMap,
'*const c_char': () => 'String',
};
const safeTemplate = `
#[inline]
pub fn {{ sname }}<{{ lifetimes }}>(&'a self
{%- for a in args -%}
, {{ a.name }}{% if a.stype %}: {% endif %}{{ a.stype -}}
{% endfor -%}
)
{%- if sret %} -> {{ sret }}{% endif %} {
{% set funccall %}
{{- name }}(
{%- for a in args -%}
{%- if not loop.first %}, {% endif %}{{ a.aconv -}}
{% endfor -%}
)
{%- endset -%}
unsafe { {{ retconv(funccall) }} }{% if not sret %};{% endif %}
}
`;
const defaultValueMap = {
'"%.0f deg"': t => 'cstr_ptr!("%.0f deg")',
'"%.3f"': t => 'cstr_ptr!("%.3f")',
'"%.6f"': t => 'cstr_ptr!("%.6f")',
'"%d"': t => 'cstr_ptr!("%d")',
'((void *)0)': t => _.startsWith(t, '*mut') ? '::std::ptr::null_mut()' : '::std::ptr::null()',
'+360.0f': t => '360.0',
'-1': t => '-1',
'-1.0f': t => '-1.0',
'-360.0f': t => '-360.0',
'0': t => _.endsWith(t, 'Flags') || t === 'ImGuiCond' ? `${t}::empty()` : '0',
'0.0f': t => '0.0',
'0.5f': t => '0.5',
'1': t => '1',
'1.0f': t => '1.0',
'100': t => '100',
'FLT_MAX': t => '::std::f32::MAX',
'ImVec2(-1,0)': t => 'ImVec2{x:-1.0,y:0.0}',
'ImVec2(0,0)': t => 'ImVec2{x:0.0,y:0.0}',
'ImVec2(1,1)': t => 'ImVec2{x:1.0,y:1.0}',
'ImVec4(0,0,0,0)': t => 'ImVec4{x:0.0,y:0.0,z:0.0,w:0.0}',
'ImVec4(1,1,1,1)': t => 'ImVec4{x:1.0,y:1.0,z:1.0,w:1.0}',
'false': t => 'false',
'sizeof(float)': t => '::std::mem::size_of::<f32>() as i32',
'true': t => 'true',
};
function indentMultilineString(indent, str) {
return _.join(_.map(_.split(str, '\n'), li => `${indent}${li}`), '\n');
}
function convertVarargs(args) {
const n = args.length;
if (n >= 2 && args[n-1].type === undefined && args[n-2].name === 'fmt') {
args.splice(n-2, 2, {
...args[n-2],
aconv: `cstr_ptr!("%s"), ${args[n-2].name}.as_ptr()`,
});
}
return args;
}
const lifetimeNames = 'abcdefghijklmnopqrstuvwxyz';
class LifetimeGen {
constructor() {
this.i = 1;
}
next() {
return lifetimeNames[this.i++];
}
}
function generateSafe() {
console.log("use super::{cstr_ptr, ImGui};");
console.log("use nsf_imgui_raw::*;");
console.log("use std::ffi::CStr;");
console.log("impl ImGui {");
const defaultConv = v => v;
const indent = " ";
const typesUsedInAPI = {};
for (const name of _.keys(definitions)) {
const funcs = definitions[name];
for (const func of funcs) {
if (func.nonUDT) { // rust works fine with UDTs
continue;
}
if (_.some(func.argsT, a => a.type === 'va_list')) { // not interesting in va_list funcs
continue;
}
const rawName = func.ov_cimguiname || func.cimguiname;
if (!_.startsWith(rawName, 'ig')) { // TODO: not interested in methods just yet
continue;
}
if (blacklistedSafeFuncs[rawName]) { // these are not safe
continue;
}
const name = snakeCase(rawName.substr(2)); // remove 'ig' prefix and convert_to_snake_case
const ret = func.ret && func.ret !== 'void' ? mapType(func.ret) : undefined;
const args = _.map(func.argsT, a => ({
name: safeArgName(a.name),
type: a.name === '...' ? undefined : mapType(a.type),
def: func.defaults[a.name],
}));
if (_.every(args, a => a.type === undefined || !!safeTypeMap[a.type]) && (!ret || !!safeRetTypeMap[ret])) {
const lifetimeGen = new LifetimeGen();
const data = {
name: rawName,
sname: name,
ret,
retconv: safeRetTypeConv[ret] || defaultConv,
sret: safeRetTypeMap[ret] ? safeRetTypeMap[ret]() : undefined,
args: convertVarargs(_.map(args, a => {
const stypef = safeTypeMap[a.type];
const stype = stypef ? (a.def !== undefined ? `impl Into<Option<${stypef(lifetimeGen)}>>` : stypef(lifetimeGen)) : undefined;
const convf = safeArgTypeConv[a.type] || defaultConv;
return {
...a,
stype,
aconv: a.def ?
`match ${a.name}.into() { Some(v) => ${convf("v")}, None => ${defaultValueMap[a.def](a.type)} }` :
convf(a.name),
};
})),
};
data.lifetimes = _.join(_.map(_.range(lifetimeGen.i), i => `'${lifetimeNames[i]}`), ', ');
for (const a of data.args) {
const t = _.startsWith(a.stype, "impl Into<Option<") ?
a.stype.substring("impl Into<Option<".length, a.stype.length-2) :
a.stype;
if (t && t[0] !== '&' && _.toUpper(t[0]) === t[0]) {
typesUsedInAPI[t] = true;
}
}
const result = nunjucks.renderString(safeTemplate, data);
console.log(indentMultilineString(indent, _.trim(result)));
} else {
console.log(indent + `// pub fn ${name} : (${_.join(_.map(args, a => a.type), ', ')}) -> ${ret}`);
}
}
}
console.log("} // impl ImGui");
console.log("pub mod types_used {");
for (const t of _.keys(typesUsedInAPI).sort()) {
console.log(indent + `pub use nsf_imgui_raw::${t};`);
}
console.log("} // mod types_used");
}
//=========================================================================================
//=========================================================================================
//=========================================================================================
program
.command("raw")
.action(() => {
generateHeader();
generateTypedefs();
generateEnums();
generateStructs();
generateFuncs();
});
program
.command("safe")
.action(() => {
generateSafe();
});
program.parse(process.argv);