obj_tpl->SetCallAsFunctionHandler(Call, Handle<Value>());

So what we've got is helpful — we've peeked into Python, said "hi", and left just as quickly. For the moment, that'sall we're going to do with python. We need to go back into Javascript-land, and figure out how to make an object thatcan wrap our adorable little PyObject*'s. We'll probably want to provide the typical javascript accessors valueOfand toString, not to mention overriding what happens when we call the objects as a function. Property access shouldbe controlled so we can attempt to load up PyObject* children of the current PyObject*. Wow! That's a mouthful.

// assuming that we have python_function_template_
//         static Persistent<FunctionTemplate> python_function_template_;

static void
Initialize(Handle<Object> target) {
    HandleScope scope;
    Local<FunctionTemplate> fn_tpl = FunctionTemplate::New();                                                
    Local<ObjectTemplate> obj_tpl = fn_tpl->InstanceTemplate();                                              

    obj_tpl->SetInternalFieldCount(1);                                                                       

    // this has first priority. see if the properties already exist on the python object                     
    obj_tpl->SetNamedPropertyHandler(Get, Set);                                                              

    // If we're calling `toString`, delegate to our version of ToString                                      
    obj_tpl->SetAccessor(String::NewSymbol("toString"), ToStringAccessor);                                   

    // Python objects can be called as functions.
    obj_tpl->SetCallAsFunctionHandler(Call, Handle<Value>());                                                

    python_function_template_ = Persistent<FunctionTemplate>::New(fn_tpl);                                   
    // let's also export "import"                                                                            
    Local<FunctionTemplate> import = FunctionTemplate::New(Import);                                          
    target->Set(String::New("import"), import->GetFunction());                                               
};       
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值