- Home /
Passing array of strings to native JavaScript plugin on WebGL
I'm working on integrating an API on a WebGL project, and I need to pass an array of strings to a native plugin. Here's a snippet of my native plugin code in JavaScript:
WebGetValues: function(textIds)
{
opt_params = {};
var ids = {};
for (var i = 0; i < textIds.length; i++)
{
ids.push(Pointer_stringify(textIds[i]));
console.log(Pointer_stringify(textIds[i]));
}
}
I'm not seeing a console log, which leads me to believe that it's either not being passed in as an array or the data is invalid. Here's how I'm passing in the string array from C#:
public void GetValues(IEnumerable<string> textIds)
{
#if UNITY_WEBGL && !UNITY_EDITOR
WebGetValues(textIds.ToArray());
return;
#endif
}
I couldn't find anything in the documentation or anywhere online about passing in string arrays to native JS plugins. Is there a way to do this?
I should mention that I have no issues passing in normal strings or returning them. I require a variable number of strings and thus must use an array.
Answer by Kimimaru · Aug 07, 2018 at 03:40 AM
I came up with a solution that involved passing in a string delimited by a less common character (Ex. ';' or '|') since I'm dealing with JSON data. On the JS side, I split the string using that delimiter, which gives me all the info I need in an array.