|
Sorry, I'm not certain what you mean by "hook native JS", but you can communicate directly with _javascript_ objects, the DOM and other stuff on the web page from Lua. _javascript_ objects look like Lua objects basically, as in the example on the REPL page you can do things like
====
local screen = js.global.screen
print("you haz " .. (screen.width*screen.height) .. " pixels")
local window = js.global -- global object in JS is the window
window.alert("hello from lua!")
window.setTimeout(function() print('hello from lua callback') end, 2500)
====That accesses the screen and window objects from JS, reads properties on them, calls methods, etc. So window.alert in Lua will call alert on the window object in JS and so forth.- Alon
On Thu, May 30, 2013 at 11:43 AM, Jeremy Darling <jeremy.darling@gmail.com> wrote:
Are you planning on adding in the ability to hook native JS similar to what we can do today with C and other native languages in Lua?- Jeremy
On Thu, May 30, 2013 at 1:31 PM, Alon Zakai <alonzakai@gmail.com> wrote:* Speed will vary by browser, depending on the power of the JS engine on this type of code (you can run a benchmark on the main page in those links). The half native speed figure from before is what I get on my machine, running Firefox nightly. But even if it is less fast on another browsers, the good thing about the JS speed race is that they all get faster in order to match whichever is better at something, so I would expect this to become fast everywhere.* This uses only standard stuff on the web - _javascript_ - and does not require anything nonstandard or proprietary (like Flash, NaCl, etc.). So it should run in any modern browser.* This is a straightforward compilation of Lua 5.2.2. So no effort is needed to recreate all the work done on Lua, we just compile it to JS like we would compile it to x86 or ARM, and get the full language "for free".Comparison to other approaches for running Lua on the web:Hi everyone,I'd like to present lua.vm.js, a new project that ports the Lua VM to _javascript_ using Emscripten. The goal is to get the full Lua language running on the web, so people can use Lua there.main page: http://kripken.github.io/lua.vm.js/lua.vm.js.html
repl: http://kripken.github.io/lua.vm.js/repl.html
blogpost with more details: http://mozakai.blogspot.com/2013/05/lua-in-_javascript_-running-vm-in-vm.htmlThe idea is that by compiling Lua to asm.js, a subset of _javascript_ that is easy to optimize, the Lua VM can run at nearly the speed it would run normally on your machine. Benchmarks show it can run at about half the speed of a native build, which should be more than enough for many use cases I think, and this is expected to improve.
Hopefully this project will be interesting to people. It would be great to get feedback and help from Lua users and developers to improve it and make it something that's useful for people.- Alon Zakai