目次

Xdef_fun

Xdef_fun(fun)
Xdef_fun_alias(fun, impl)

XTAL_BINDマクロのスコープ内で呼び出すことでそのクラスの静的メンバ関数funをバインドすることができます。alias版はfunという名前で関数implをバインドすることができます。

普通の関数をクラスの静的メソッドとしてバインドしたいときには、Class::def_fun(Xid(fun), &fun)もしくはXdef(Xid(fun), xtal::fun(&fun))を使います。

Example

C++

class Foo{
public:
    Foo(){
    }
 
    void print() const{
        StringPtr("foo")->p();
    }
 
    void static doublePrint(const Foo& foo){
        foo.print(); foo.print();
    }
};
 
void Foo_doublePrint(const Foo& foo){
    foo.print(); foo.print();
}
 
XTAL_PREBIND(Foo){
    Xdef_ctor0();
}
XTAL_BIND(Foo){
    Xdef_fun(doublePrint);
    Xdef_fun_alias(doublePrint2, &Foo_doublePrint);
    //or it->def_fun(Xid(doublePrint2), &Foo_doublePrint);
    //or Xdef(Xid(doublePrint2), fun(&Foo_doublePrint));
}
 
void exec_xtal(){
    xtal::global()->def(Xid(Foo), xtal::cpp_class<Foo>());
    Xsrc((
            foo : Foo();
            foo.p;
            Foo::doublePrint(foo);
            Foo::doublePrint2(foo);
    ))->call();
}

Output

<(instance of lib::builtin::global::Foo)>
foo
foo
foo
foo