lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Continuing on my quest of not using JS anymore for websockets, the websocket object
needs to call fields like "onopen", "onmessage", ...

Do you think this could be supported ?
Something like that would be the simpliest way I imagine:

local ws = js.new.WebSocket("ws://whatever", "something")
ws.onopen = function(self, ...)
	print("connected!")
end

"self" would be taken from the JS "this" automatically, so we could even write:
function ws:opopen(...) end

Sorry to bother you with all that, it's just that lua on a browser is so exiting... :)

On 03 Jun 2013 00:58:28 +0200
Alon Zakai <alonzakai@gmail.com> wrote:

> We are compiling the entire Lua 5.2.2 VM to JavaScript here, we aren't
> compiling specific Lua code into specific JavaScript code. Although, we are
> trying to keep the syntax close, so
> 
>   js.new.Object(...)
> 
> in Lua instead of
> 
>   new Object(...)
> 
> So it might look like we are translating it directly even if that is not
> the case.
> 
> - Alon
> 
> 
> 
> On Sun, Jun 2, 2013 at 3:55 PM, PythonicLuiacOutlook <
> pythonicluiac@outlook.com> wrote:
> 
> >  Is it even possible to translate Lua to JavaScript?(I'm new to Lua, so
> > I'm most likely to be wrong.
> >
> > --- Original Message ---
> >
> > From: "Alon Zakai" <alonzakai@gmail.com>
> > Sent: 2 June 2013 23:52
> > To: "Lua mailing list" <lua-l@lists.lua.org>
> > Subject: Re: lua.vm.js - Lua VM, on the Web
> >
> >    So far I ended up with
> >
> >    js.new.WebSocket(...)
> >
> >  which I kind of like. Do you prefer a different syntax over that one?
> >
> >  - Alon
> >
> >
> >
> > On Sun, Jun 2, 2013 at 1:40 PM, Nicolas <nicolas@net-core.org> wrote:
> >
> > On 02 Jun 2013 18:10:18 +0200
> > Alon Zakai <alonzakai@gmail.com> wrote:
> >
> > > That's a missing feature, I forgot about that. Should be easy to add
> > > though. How about an api like
> > >
> > > js.new('WebSocket', arg1, arg)
> > >
> > > which will call   new WebSocket(arg1, arg2)?
> >
> >  Sounds god, hum perhaps even better looking would be:
> > js.global.WebSocket.new(...)
> > If you can have some smart metatable on it it could work
> > Or at least:
> > js.new(js.global.WebSocket, ...)
> >
> > ?
> >
> > > - Alon
> > >
> > >
> > >
> > > On Sun, Jun 2, 2013 at 5:00 AM, Nicolas <nicolas@net-core.org> wrote:
> > >
> > > > On 01 Jun 2013 03:52:50 +0200
> > > > Alon Zakai <alonzakai@gmail.com> wrote:
> > > >
> > > > > I added the ability to write HTML script tags in Lua, example here
> > > > > http://kripken.github.io/lua.vm.js/script_example.html
> > > > > Do "view source" on the page to see the Lua in it.
> > > >
> > > > Very nifty (that and the whole thing).
> > > >
> > > > Is there support for javascript "new" oeprator?
> > > > As in if in lua I wanted to do the equivalent of JS "new
> > > > WebSocket(...)" I tried with a js.run() call but it returned 0
> > > > instead of the websocket
> > > >
> > > > >
> > > > > - Alon
> > > > >
> > > > >
> > > > >
> > > > > On Thu, May 30, 2013 at 11:31 AM, Alon Zakai <alonzakai@gmail.com>
> > > > > wrote:
> > > > >
> > > > > > 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.html
> > > > > >
> > > > > > The 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.
> > > > > >
> > > > > > Comparison to other approaches for running Lua on the web:
> > > > > >
> > > > > > * 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".
> > > > > >
> > > > > > * 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.
> > > > > >
> > > > > > * 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.
> > > > > >
> > > > > > 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
> > > > > >
> > > > > >
> > > >
> > > >
> >
> >
> >