Skip to content
Merged
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
2 changes: 1 addition & 1 deletion src/lib/libembind_gen.js
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ var LibraryEmbind = {
out.push(`export type ${this.name} = {\n`);
const outFields = [];
for (const {name, type} of this.fields) {
outFields.push(` ${name}: ${nameMap(type)}`);
outFields.push(` ${name}${type instanceof OptionalType ? '?' : ''}: ${nameMap(type)}`);
}
out.push(outFields.join(',\n'))
out.push('\n};\n\n');
Expand Down
2 changes: 2 additions & 0 deletions test/other/embind_tsgen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ struct ValObj {
Bar bar;
std::string string;
CallbackType callback;
std::optional<int> optionalInt;
ValObj() : callback(val::undefined()) {}
};

Expand Down Expand Up @@ -209,6 +210,7 @@ EMSCRIPTEN_BINDINGS(Test) {
value_object<ValObj>("ValObj")
.field("string", &ValObj::string)
.field("bar", &ValObj::bar)
.field("optionalInt", &ValObj::optionalInt)
.field("callback", &ValObj::callback);
function("getValObj", &getValObj);
function("setValObj", &setValObj);
Expand Down
1 change: 1 addition & 0 deletions test/other/embind_tsgen.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export type ValArr = [ number, number, number ];
export type ValObj = {
string: EmbindString,
bar: Bar,
optionalInt?: number | undefined,
callback: (message: string) => void
};

Expand Down
1 change: 1 addition & 0 deletions test/other/embind_tsgen_ignore_1.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ export type ValArr = [ number, number, number ];
export type ValObj = {
string: EmbindString,
bar: Bar,
optionalInt?: number | undefined,
callback: (message: string) => void
};

Expand Down
1 change: 1 addition & 0 deletions test/other/embind_tsgen_ignore_2.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export type ValArr = [ number, number, number ];
export type ValObj = {
string: EmbindString,
bar: Bar,
optionalInt?: number | undefined,
callback: (message: string) => void
};

Expand Down
1 change: 1 addition & 0 deletions test/other/embind_tsgen_ignore_3.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export type ValArr = [ number, number, number ];
export type ValObj = {
string: EmbindString,
bar: Bar,
optionalInt?: number | undefined,
callback: (message: string) => void
};

Expand Down
7 changes: 7 additions & 0 deletions test/other/embind_tsgen_main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ import moduleFactory from './embind_tsgen.js';
callback: () => {}
});

module.setValObj({
bar: module.Bar.valueOne,
string: "ABCD",
callback: () => {},
optionalInt: 99
});

const valObj = module.getValObj();
// TODO: remove the cast below when better definitions are generated for value
// objects.
Expand Down
1 change: 1 addition & 0 deletions test/other/embind_tsgen_module.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export type ValArr = [ number, number, number ];
export type ValObj = {
string: EmbindString,
bar: Bar,
optionalInt?: number | undefined,
callback: (message: string) => void
};

Expand Down