Skip to content
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

[[cheerp::jsexport]] improvements #54

Closed
uMaxmaxmaximus opened this issue Feb 9, 2017 · 2 comments
Closed

[[cheerp::jsexport]] improvements #54

uMaxmaxmaximus opened this issue Feb 9, 2017 · 2 comments

Comments

@uMaxmaxmaximus
Copy link

uMaxmaxmaximus commented Feb 9, 2017

class [[cheerp::jsexport]] Cat {
public:
    int age;
    Cat(int age) : age(age) {}

    void say() {
        console.log(age);
    }
};

in javascript

var cat  = new Cat(10);


// under the hood js object:
cat = {
  get age() { return this.i0; },
  set age(value) { this.i0 = value >> 0; },
  say() { return cppFuncName(this) }
}
@carlopi
Copy link
Contributor

carlopi commented Jul 1, 2020

Fields have been ruled out of cheerp::jsexport scope.
So in this case (if you are interested in the getter and/or setter) you will have to define get/set on your own.

Once added function int get_age() e void set_age(int), this is the resulting code:

"use strict";
/*Compiled using Cheerp (R) by Leaning Technologies Ltd*/
var __imul=Math.imul;
var __fround=Math.fround;
var oSlot=0;var nullArray=[null];var nullObj={d:nullArray,o:0};
function __ZN3Cat3sayEv(Lthis){
        console.log(String(Lthis.i0|0));
}
function __ZN3CatC1Ei(Lthis,Lage){
        Lthis.i0=Lage;
}
function __ZN3Cat7set_ageEi(Lthis,Lx){
        Lthis.i0=Lx;
}
function __ZN3Cat7get_ageEv(Lthis){
        return Lthis.i0|0;
}
function Cat(a0){
        this.i0=0;
        ;
        this.d=[this];
        if (arguments.length===1&&arguments[0]===undefined){
                return;
        }
        __ZN3CatC1Ei(this,a0);
};
Cat.prototype.get_age=function (){ 
        return __ZN3Cat7get_ageEv(this);
};
Cat.prototype.set_age=function (a0){
        return __ZN3Cat7set_ageEi(this,a0);
};
Cat.prototype.say=function (){ 
        return __ZN3Cat3sayEv(this);
};
Cat.promise=
Promise.resolve();

@carlopi
Copy link
Contributor

carlopi commented Jul 1, 2020

To note that fields are allowed as public or private fields, and will be simply transparent to [[cheerp::jsexport]].

@carlopi carlopi closed this as completed Jul 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants