开发者

need to return multiple values from NPAPI function

开发者 https://www.devze.com 2023-03-20 09:15 出处:网络
I am trying to create an NPAPI plugin where I call a javascript function and return some value from plugin. I did this by setting fields in NPVariant pointer. But since its a structure, I can put only

I am trying to create an NPAPI plugin where I call a javascript function and return some value from plugin. I did this by setting fields in NPVariant pointer. But since its a structure, I can put only one string at a time. In few开发者_JAVA百科 cases I need to return multiple values or array from NPAPI function to javascript. Any idea about how to achieve this?


The only way I know of to accomplish what you want is to return a javascript array; there are two ways you can get such an array. The first (and in my opinion ideal) way is to get the window NPObject by calling NPN_GetValue and then invoke "array" and the second is to use NPN_Evaluate.

Once you have the array (it'll be an NPObject) you can invoke push on it with the items you want to add.

This is what FireBreath does when you return a FB::VariantList (a vector of FB::variant objects); it just creates an array, stuffs them all in, and then returns that NPObject. Thus this is a tested and reliable solution. You can also call window.object() and then SetProperty to return a javascript object; arrays area also objects, so you could even make a hybrid that is both an array (indexed) and an object (key->val).

0

精彩评论

暂无评论...
验证码 换一张
取 消