- for k,v in pairs({'foo','bar'}) do print(k,v) end
- for x = 1,10 do print(x) end
- for k,v in pairs(_G) do print("->", k,v) end
The output seems ok, but I'm not totally sure that it's 100% correct, since my Lua skills are pretty rusty. That's also why I didn't notice the issues in the beginning - I saw that 'hello world' worked, and thought all was well ;)
If people really want to see this work properly, let me know about any other problems. I'm happy to work on it, I just can't do it without feedback since I don't know where to start testing. (Is there a standard test suite for Lua?)
The issues that had to be fixed in Emscripten were
- Lua uses varargs in ways that the existing code didn't support. So I improved that. Varargs are now emulated in a way that is basically identical to C.
- A few missing stdlib functions.
Still doesn't work. I tried with this code:
ReplyDeleteio.write("Hello world, from ",_VERSION,"!\n")
Found on the Lua Web Demo: http://www.lua.org/cgi-bin/demo
For loops only seem to work in Firefox, broken in chrome and opera.
ReplyDeletelazza: I'd be pretty scared if io functions worked..
Why? I don't know LUA so please be patient with me. :)
ReplyDeleteI found the example on the official website so I tought it was appropriate...
Thanks for the feedback Lazza and TheAncientGoat!
ReplyDelete@Lazza: Hmm, to be honest I don't know Lua much either ;) But if you replace |io.write| with |print| then that code will work.
I suspect as the TheAncientGoat says, it is trying to do IO to a file or something, and running on the web won't allow that...
@TheAncientGoat: Ah, it seems to only work in browsers that support typed arrays right now... will have a fix up shortly.
Ok, uploaded a fix. Stuff should now work in all browsers, including those without typed arrays. Tested on Chrome and Firefox. Please let me know if something is broken.
ReplyDeleteJust tried a few examples from http://lua-users.org/wiki/MathLibraryTutorial and many of the functions didn't work (but some did). The following didn't work:
ReplyDeletemath.floor
math.ceil
math.pow (x^y doesn't work either)
math.log
math.exp
math.frexp
math.ldexp
math.log
math.log10
math.modf
math.random
math.randomseed
and "/bin/this.program: (error object is not a string)" was displayed in response on the webpage.
http://lua-users.org/lists/lua-l/2008-06/msg00124.html contains tests for Lua 5.1. If you want to add tests for non-C/C++ languages, Lua might be a candidate.
Using Emscripten to run the Lua interpreter (not LuaJIT?) in the browser seems like a fun way to learn the language. I'm a Lua newbie.
Maybe I'll give the Lua LLVM front end a try and feed the generated bitcode into Emscripten...not as fun as running the entire VM but maybe it'll be a faster and smaller way of running Lua apps in the browser. Accessing the DOM is going to be a problem...unless I'm missing something.
Thanks for the great work.
@Dave
ReplyDeleteGoing through the Lua LLVM frontend would be better, yeah. Let me know if you get that working, or if I can help!
The Lua demo page ( http://syntensity.com/static/lua.html ) mentions the needs for a Lua syntax highlighter. Codemirror ( http://codemirror.net/ ) supports this now, so switching Skywriter to Codemirror will do the trick.
ReplyDelete/phil