Open TonyStarkBy opened 7 years ago
There is no way to call a Lua function directly from JS (I can't think of one at least)
There is however an example to run Lua code by passing data to the app in the html code: Search for "SetTextData". This in turn calls the custom js library MYTESTLIBRARY.SetTestData(txt), which in turn sets the data. That data is later picked up by the engine, and when the lua function html5nativeext.get_data() returns that string, you can use "loadstring()" to run that code (which is Lua code).
As for calling JS from Lua, you can either use our new module html5.run() or take a look at emscripten_run_script()
It something like waiting changes in update function?
hmm.. What about cwrap or ccall ? https://kripken.github.io/emscripten-site/docs/porting/connecting_cpp_and_javascript/Interacting-with-code.html
Well although ccall/cwrap does seem like it's one step closer to what you want, I'm still not sure how that would work in terms of running on the main thread of the engine, or rather, when the correct Lua context is active.
As for calling JS from Lua, you can either use our new module html5.run()
Ok, it can be used.
There is no way to call a Lua function directly from JS (I can't think of one at least)
Hmm... So current solution is to implement "hand made function call queue?" based on "on_update" function? :(((
I was expecting that with native extension I could make something like this: https://docs.unity3d.com/Manual/webgl-interactingwithbrowserscripting.html
@TonyStarkBy In the example link you gave, it was an example of calling JavaScript from the engine? I couldn't see an example of how to interact with the engine from the index.html side?
Btw, I also posted a small example on our forum
too many Update calls in lua is not good decision especially in html5 target, as I think. And this is contradicts of engine reactive paradigm.
Can you add example of code how call lua function from JS and from lua call JS function?