NPAPI 플러그인을 쓰고 있습니다. C++ 코드에서는 NPAPI를 사용하여 JS 개체를 만들 수 없습니다.NPAPI를 사용하여 새 JS 객체를 만드는 방법은 무엇입니까?
Foo.js
function Foo(p)
{
this.a=p;
}
Foo.prototype.get=function()
{
return this.a;
}
C++ 코드 (난 그냥 우리가 JS에서 할 수있는 링크 푸 객체를 생성 할 VAR들 = 새로운 푸 :.. 나는이 방법을 시도 (2) 우리는 JS 코드에 jsFoo1 및 jsFoo2을 반환하는 경우)
int newJSObject(const NPP instance,const NPNetscapeFuncs* npnfuncs,const string objectName,
const NPVariant* args,const int argsCount,NPVariant& result)
{
int status;
NPObject *winobj;
npnfuncs->getvalue(instance,NPNVWindowNPObject,&winobj);
NPVariant npJS;
NPIdentifier npJSId=npnfuncs->getstringidentifier(objectName.c_str());
status=npnfuncs->getproperty(instance,winobj,npJSId,&npJS);
NPObject* npObjJS = NPVARIANT_TO_OBJECT(npJS);
NPVariant npPrototype;
NPIdentifier npPrototypeId=npnfuncs->getstringidentifier("prototype");
status=npnfuncs->getproperty(instance,npObjJS,npPrototypeId,&npPrototype);
NPObject* npObjPrototype = NPVARIANT_TO_OBJECT(npPrototype);
NPVariant npJSConstructor;
NPIdentifier npJSConstructorId=npnfuncs->getstringidentifier("constructor");
status=npnfuncs->invoke(instance,npObjPrototype,npJSConstructorId,
args,argsCount,&npJSConstructor);
/*
* destroy memory
* */
npnfuncs->releaseobject(winobj);
npnfuncs->releasevariantvalue(&npJS);
npnfuncs->releasevariantvalue(&npJSConstructor);
result=npJS;
return status;
}
NPVariant jsFoo1;
NPVariant arg;
DOUBLE_TO_NPVARIANT(2,arg);
NPVariant prams[]={arg};
newJSObject(instance,npnfuncs,"Foo",prams,sizeof(prams)/sizeof(prams[0]),jsFoo);
NPVariant jsFoo2;
NPVariant arg;
DOUBLE_TO_NPVARIANT(3,arg);
NPVariant prams[]={arg};
newJSObject(instance,npnfuncs,"Foo",prams,sizeof(prams)/sizeof(prams[0]),jsFoo);
을하지만, 우리는() Fooxxx.get를 호출합니다. jsFoo1 및 jsFoo2 모두 "생성자"
이 가사람이 나에게이 NPAPI를 사용하여 C++에서 JS 개체를 만드는 다른 방법을 줄 수 3. 내가 문제가 알고있다?
NPN_Evaluate를 사용하여 스크립트를 삽입하면 고마워요. FireBreath의 소스 코드를 읽는 중입니다. 회신을 보내면 ... – greatsea