Quantcast
Channel: Answers by "gfoot"
Viewing all articles
Browse latest Browse all 95

Answer by gfoot

$
0
0
If you want to pass it straight to a C# function, you need to marshal it somehow. You can either marshal it as an object, and have a C# struct with the same layout that gets filled in, or you can pass the two elements as separate string parameters to the same function. Either way, to do this you need to use direct C# method calls from the Javascript, rather than SendMessage, and it requires some care. Using SendMessage with JSON.stringify(data) is certainly easier, if you have the ability to parse the JSON from C# and don't mind the latency of SendMessage. If you think about it though, there's a crazy amount of inefficiency here. Another approach that might work is to pull the data from C# instead of pushing it from Javascript. e.g. bind emscripten_run_script_string and use that: [DllImport("__Internal")] extern static string emscripten_run_script_string(string script); ... string username = emscripten_run_script_string("data.username"); string message = emscripten_run_script_string("data.message"); I think this should work in theory, but I haven't tried it. Obviously it requires "data" to be a javascript global - if it's not, you need to change the script code to some other way of accessing the data.

Viewing all articles
Browse latest Browse all 95

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>