As @pkeod mentioned, the html5.run()
is the simplest way of communicating. And if you are waiting for a reply, you can poll the result yourself.
E.g. (A quick test, no native extensions needed):
function init(self)
html5.run("start_processing()")
end
function update(self, dt)
-- poll the result
local result = html5.run("get_processing_result()") -- calling function in index.html
if result ~= "" then -- Or whatever your function returns as "no result"
print("YAY, the processing is done! Result: ", result)
end
end
The .html template file contains this:
<script type='text/javascript'>
processing = -1
function start_processing()
{
processing = 5;
}
function get_processing_result()
{
if( processing > 0 )
{
processing--;
if( processing == 0 )
{
processing = -1; // stop processing
return "TEXT FROM JS"; // stop processing
}
}
return ""; // empty means no result
}
</script>
And, in the end, I get the output:
DEBUG:SCRIPT: YAY, the processing is done! Result: TEXT FROM JS
What is your use case? What do you want to do?