diff --git a/lib/generateffi.js b/lib/generateffi.js index 215e2fe..dae4fd3 100644 --- a/lib/generateffi.js +++ b/lib/generateffi.js @@ -163,8 +163,20 @@ exports.generate = function (opts) { } else if (this.kind == Cursor.FieldDecl && this.type.kind == Type.Unexposed) { //console.error('FieldDecl', this.type.kind, this.type.spelling); t = wrap.elements[wrap.elements.length - 1]; - t.name = this.spelling; - return Cursor.Continue; + /* This may not be entirely correct, we're assuming that because we + * already have elements defined that we're at the name of it, + * consider `union { int foo; } myUnion;` but it's also possible + * we are at an actual definition and we should be defining this type + * + * TODO -- man I need tests. + */ + if (t) { + t.name = this.spelling; + return Cursor.Continue; + } else { + t = defineType(this.type.declaration); + tname = this.spelling; + } } else { t = mapType(this.type, this.spelling); tname = this.spelling;