zitsky / tiny-js

Automatically exported from code.google.com/p/tiny-js
0 stars 0 forks source link

i have made a small wrapper with hours #15

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
when add callback function,just like this:

class cboy
{
public:
    int add_age(int n) 
    {
        m_age += n;
        return m_age; 
    }

    void set_name(string name) 
    {
    }

    string do_some_thing(int n, double d, string str)
    {
        return "ok";
    }
private:
    int m_age;
};

static double mySqr(double d)
{ 
    return d*d;
}

static string myStringConcat(string strL, string strR) 
{
    return strL+strR;
}

static double myDoSomeThing(int n, double d, string str1, string str2)
{
    return n+d;
}

void test(CString str1)
{
    CTinyJS_Wrapper s;

    cboy boy;
    s.addExFun( MakeFunObj<int, Seq<int>>("add_boy_age", &boy, &cboy::add_age) );
    s.addExFun( MakeFunObj<void, Seq<string>>("set_boy_name", &boy, &cboy::set_name) );
    s.addExFun( MakeFunObj<string, Seq<int,double,string>>("boy_do_some_thing", &boy, &cboy::do_some_thing) );

    s.addExFun( MakeFunObj<double, Seq<double>>("sqr", &mySqr) );
    s.addExFun( MakeFunObj<string, Seq<string, string>>("strcon", &myStringConcat) );
    s.addExFun( MakeFunObj<double, Seq<int, double, string, string>>("do_some_thing", &myDoSomeThing) );

...
}

my email:kanbang@163.com
sorry for poor english

Original issue reported on code.google.com by kanb...@163.com on 22 Mar 2013 at 11:37

Attachments: