physx-js-webidl
physx-js-webidl copied to clipboard
Flag/Enums are verbose
From what it looks like, the only way to access the flag enums is via
PhysX._emscripten_enum_PxBaseFlagEnum_eOWNS_MEMORY()
I think they should be more like PhysX.PxBaseFlagEnum.eOWNS_MEMORY
I completely agree. Unfortunately, this is caused by the way the emscripten WebIDL generator generates the enum accessors
As far as I know, the only way to achieve the pattern would be to hand-write additional appropriately named C++ classes which provide the enum values as integer constants, which would be very fiddely and error-prone.
I opened an issue regarding this a while ago. But so far nothing seems to have changed.
const fixEnums = () => {
const enums = Object.keys(PhysX)
.filter(key => {
return key.includes('_emscripten_enum_');
})
.map(enumString => {
const split = enumString.split('_emscripten_enum_')[1].split('();')[0].split('_e');
return { enumName: split[0], entryName: split[1], emscript: enumString };
});
for (const enumEntry of enums) {
if (!PhysX[enumEntry.enumName]) {
PhysX[enumEntry.enumName] = {};
}
PhysX[enumEntry.enumName][enumEntry.entryName] = PhysX[enumEntry.emscript]();
}
};
A little hack I use to fix the enums in JS