在 V8 中使用访问器时出现问题
我正在围绕 V8 引擎编写一个包装类,以便最终我能够做这样的事情
script->createClass("Test");
script->getClass("Test")->addFunction("funct1",testfunct1);
script->getClass("Test")->addVariable("x",setter,getter);
到目前为止,我可以创建类并向它们添加函数,它工作得很好,但是我在添加变量时遇到了问题。
我的类模板是这样存储的
Persistent<Object> classInstance;
,我尝试添加一个像这样的访问器:
this->classInstance->SetAccessor(String::New(variableName),setter,getter);
编译此代码给我一个错误,即 v8::Object 没有 SetAccessor 函数(尽管我已经看到 doxygen 文档另有说明)。
所以我的问题是:我该如何解决这个问题?是否可以将对象转换为对象模板?
I'm writing a wrapper class around the V8 engine so that eventually I'll be able to do something like this
script->createClass("Test");
script->getClass("Test")->addFunction("funct1",testfunct1);
script->getClass("Test")->addVariable("x",setter,getter);
So far I can create classes and add functions to them and it works perfectly, however I have encountered a problem with adding variables.
My class template is stored as such
Persistent<Object> classInstance;
and I try to add an Accessor like this:
this->classInstance->SetAccessor(String::New(variableName),setter,getter);
Compiling this code gives me the error that v8::Object doesn't have a SetAccessor function (though I've seen doxygen documentation that says otherwise).
So my question is: How can I fix this? Is it possible to cast an Object to an ObjectTemplate?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Object
上的SetAccessor
自 2010 年 5 月发布的 V8 2.2.12 起可用。(在此之前,它确实仅在ObjectTemplate
上可用) .) 您或许应该更新您的 V8 副本。SetAccessor
onObject
is available as of V8 2.2.12, which was released May 2010. (Before that, it was indeed only available onObjectTemplate
.) You should probably update your copy of V8.