...or should I just use percent-encoding for binary data?
Dirk
Sure. Create a JavaScript Array object (using NPN_Evaluate("[]") or
something equivalent), and then add each element to it.
> i had a look at NPVariant but there doesn't seem to be support for returning arrays..
An array is just a kind of JS object.
--BDS
You can then add items to the array by using NPN_Invoke to call push
on the array NPObject.
FireBreath uses this; in fact, you might want to consider using
FireBreath, as it simplifies all of this. http://firebreath.googlecode.com
The FireBreath code for doing this can be found here:
http://code.google.com/p/firebreath/source/browse/src/NpapiPlugin/NpapiBrowserHost.cpp#174
Keep in mind that FireBreath uses an abstraction for this feature
rather than using NPN_* methods directly, but at least the general
concept is there, and if you dig a little you can find what is
actually getting called.
Richard
function rcon (ip, port, command)
{
var udp_socket = document.getElementById('udp_socket_plugin');
udp_socket.open (ip, port);
// because of JavaScript binary data must be percent-encoded
udp_socket.write ('%ff%ff%ff%ff' + command);
var s = udp_socket.read ();
udp_socket.close ();
// strip 4 bytes header (also percent-encoded)
s = unescape (s.substring (12));
for (var i = 0; i < s.length; i++)
{
s = s.replace ('\\', '<br>');
s = s.replace ('\\', '=');
}
document.getElementById ('udp_socket_plugin_output').innerHTML = s;
}
it works.. and is small...
Dirk
> _______________________________________________
> dev-tech-plugins mailing list
> dev-tech...@lists.mozilla.org
> https://lists.mozilla.org/listinfo/dev-tech-plugins
>
ok.. i had a look at firebreath and it's abstraction... it made me use google and i found this one instead..
http://stackoverflow.com/questions/1896166/npvariant-to-string-array
so this is how far i have come getting an array from javascript into the npruntime sample
bool
ScriptablePluginObject::Invoke (NPIdentifier name, const NPVariant * args,
uint32_t argCount, NPVariant * result)
{
if (name == sTest_id)
{
NPObject *inObject = args[0].value.objectValue;
NPVariant npvLength;
NPN_GetProperty(mNpp, inObject, NPN_GetStringIdentifier("length"), &npvLength);
for (uint32_t i = 0; i < npvLength.value.intValue; i++)
{
NPVariant curValue;
NPN_GetProperty(mNpp, inObject, NPN_GetIntIdentifier(i), &curValue);
printf ("%s", curValue);
}
return true;
}
return false;
}
it doesn't work
Dirk
sorry.. i got demotivated too fast... it *does* work now... i fixed what i did with the printf there... i am going to get the
other way working too now..
and, yes, i have realized that post is from you too... xD
Dirk