Hi,
I was trying to port a C++ library to JS and now I'm still testing "embind"
on several cases.
What I've done is building a library both in C++ and JS. Then use the api
both in C++ / handwritten JS demo.
Everything is great except for some questions...
1. How can I embind a global variable ??
In my header:
extern "C"
{
static const int STATIC_INT_CONSTANT_OUTSIDE_CLASS = 5000;
static int STATIC_INT_VARIABLE_OUTSIDE_CLASS;
}
then
EMSCRIPTEN_BINDINGS(TESTLIB)
{
constant("STATIC_INT_CONSTANT_OUTSIDE_CLASS",
STATIC_INT_CONSTANT_OUTSIDE_CLASS);
// how to do with the variable ???
}
2. How can I embind a STATIC const, STATIC variable, and enum INSIDE a
class ??
class AbstractClass
{
public:
typedef enum
{
EIC = 1
} EInsideClass;
public:
static const int STATIC_INT_CONSTANT_INSIDE_CLASS;
static int STATIC_INT_VARIABLE_INSIDE_CLASS;
};
// Want to use Module.AbstractClass.EInsideClass.EIC,
Module.AbstractClass.STATIC_INT_CONSTANT_INSIDE_CLASS and
Module.AbstractClass.STATIC_INT_VARIABLE_INSIDE_CLASS in my JS
3. Can't I bind ".constructor<>()" when embinding an abstract class ?
4. This one may be my bug but I just can't figure it out:
I wrote a base class in C++: ( And its wrapper of course )
class BaseClass : public AbstractClass
{
public:
BaseClass() {};
BaseClass( int p1, bool p2 ) : intMemberData(p1), boolMemberData(p2) {};
~BaseClass() {};
virtual void SetIntMemberData( int data ) { intMemberData = data; };
virtual void SetBoolMemberData( bool data ) { boolMemberData = data; };
virtual int GetIntMemberData() { return intMemberData; };
virtual bool GetBoolMemberData() { return boolMemberData; };
protected:
int intMemberData;
bool boolMemberData;
};
Now I'm trying to extend it in my JS:
var JS_UserCustomClass = Module.BaseClass.extend( "BaseClassWrapper",
{
__construct: function()
{
this.__parent.__construct.call(this); // 1. Can I just pass the first 2
params ?
console.log(arguments); // 2. each value is correct in arguments !
//this.intMemberData = arguments[0]; // 3. Produce a wrong result
//this.boolMemberData = arguments[1]; // 4. Produce a wrong result
this.SetIntMemberData( arguments[0] );
this.SetBoolMemberData( arguments[1] );
this.newData = arguments[2];
},
SetNewMemberData: function(input) { this.newData = input; },
GetNewMemberData: function() { return this.newData; },
newData:0,
});
var CustomC = new JS_UserCustomClass( 56, true, 512 );
console.log( "==== Getter (int, bool, int): ( %d, %d, %d )",
CustomC.GetIntMemberData(), CustomC.GetBoolMemberData(),
CustomC.GetNewMemberData() );
------
First, when I call the parent's constructor, can I pass the first 2
parameters into the call(this, ____? ) just like we do in C++:
C_UserCustomClass( int p1, bool p2, int p3 ) : BaseClass(p1, p2),
newData(p3) {};
Second, if I set the values directly to the variables, it produces
incorrect result ( which is: 0, 0, 512) but the values in arguments are all
correct.
So somehow I have to set through a setter, then the result will be
correct ( in the case above, the console shows: 56, 1, 512 )
(Only happens in constructor)
Sorry I ask lots of questions, I'd be very glad if someone can help me with
these. Thx! =D
--
You received this message because you are subscribed to the Google Groups
"emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.