-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Function parameters incorrectly typed as number for classes extending another class #270
Comments
Thanks for raising this issue! I'll find some time to look at this soon. |
This is related to some logic for generating correct types for javascript subclasses of c++ classes using JSImplementation (see: https://emscripten.org/docs/porting/connecting_cpp_and_javascript/WebIDL-Binder.html#sub-classing-c-base-classes-in-javascript-jsimplementation). For example, in ammo.js Ammo.ConcreteContactResultCallback is used to get collision results. Here is it's webidl: [Prefix="btCollisionWorld::"]
interface ContactResultCallback {
float addSingleResult([Ref] btManifoldPoint cp, [Const] btCollisionObjectWrapper colObj0Wrap, long partId0, long index0, [Const] btCollisionObjectWrapper colObj1Wrap, long partId1, long index1);
};
[JSImplementation="ContactResultCallback"]
interface ConcreteContactResultCallback {
void ConcreteContactResultCallback();
float addSingleResult([Ref] btManifoldPoint cp, [Const] btCollisionObjectWrapper colObj0Wrap, long partId0, long index0, [Const] btCollisionObjectWrapper colObj1Wrap, long partId1, long index1);
}; With emscripten webidl bindings, the javascript implementation of class ContactResultCallback {
addSingleResult(cp: btManifoldPoint, colObj0Wrap: btCollisionObjectWrapper, partId0: number, index0: number, colObj1Wrap: btCollisionObjectWrapper, partId1: number, index1: number): number;
}
class ConcreteContactResultCallback extends ContactResultCallback {
constructor();
addSingleResult(cp: number, colObj0Wrap: number, partId0: number, index0: number, colObj1Wrap: number, partId1: number, index1: number): number;
} My understanding was that classes that use JSImplementation are used for callbacks, and the methods are generally not called from the javascript side. Classes using JSImplementation need to have all methods implemented in javascript. Is the MotionState class in ammo.js something that is meant to be called in javascript? I also noted there is class btMotionState {
getWorldTransform(worldTrans: btTransform): void;
setWorldTransform(worldTrans: btTransform): void;
}
class MotionState extends btMotionState {
constructor();
getWorldTransform(worldTrans: number): void;
setWorldTransform(worldTrans: number): void;
}
class btDefaultMotionState extends btMotionState {
constructor(startTrans?: btTransform, centerOfMassOffset?: btTransform);
get_m_graphicsWorldTrans(): btTransform;
set_m_graphicsWorldTrans(m_graphicsWorldTrans: btTransform): void;
m_graphicsWorldTrans: btTransform;
} |
Thank you so much for your help, @isaac-mason 😄
It is. Both
Ah, interesting point, you're right. So it's not guaranteed that an extending class will have incorrect types
Do you think this means we need to make changes on the ammo.js side? Perhaps the IDL file or deeper in the Bullet C++ source? |
No worries @regnaio!
Only interfaces in idl that use JSImplementation will have numeric argument types to match what emscripten generates. Other types of inheritance aren't affected by this logic, that's right.
I'm not familiar with the |
My apologies if this is related to #200
Inside the https://github.com/kripken/ammo.js repo, I ran:
I noticed that for classes that
extends
another class, function parameter types appear to be incorrectly typed asnumber
:Instead, if we use
@milkshakeio/webidl2ts
, then we get the correct result:I still prefer to use
webidl-dts-gen
over@milkshakeio/webidl2ts
, since it handlesenum
s correctly.Thank you for all your help!
The text was updated successfully, but these errors were encountered: