LUA Vs Javascript

classic Classic list List threaded Threaded
61 messages Options
1234
Reply | Threaded
Open this post in threaded view
|

LUA Vs Javascript

James Kimble

Not trying to start any kind of fire fight AT ALL. Just wanting to compare technologies. One I'm familiar with, the other completely new to.

I'm in the process of assessing various technologies for use on an embedded platform intended to operate as a control interface to something else (doesn't matter what here). We've got a local GUI on 1/4 VGA display that we want to duplicate (though improve the look of) as a web based GUI. My first thought was HTML with Javascript (Our boa web server doesn't seem to do much else). A developer suggested Lua as an alternative. I've looked through some of the documentation and played with it a little and it looks like a great little language. However I'm not really seeing any advantage to what I was planning to do with Javascript (Graphics and things that are more difficult with HTML).

Can someone experienced with Lua please comment. I don't want to discourage a good new technology from entering into use in our device. I would welcome that if it makes sense. What I'm not sure of is, does it make sense?

Reply | Threaded
Open this post in threaded view
|

Re: LUA Vs Javascript

Javier Guerra Giraldez
On Fri, Jun 27, 2008 at 2:33 PM, James Kimble <[hidden email]> wrote:
>
> Not trying to start any kind of fire fight AT ALL. Just wanting to compare
> technologies. One I'm familiar with, the other completely new to.

Lua and JavaScript have a lot in common.  (that's a little surprising,
especially for some like me, that absolutely love Lua and find
JavaScript unforgivably ugly :-)

common points:
- really dynamic language
- all objects are hash tables
- you can access fields like obj.field, or obj[field]
- functions are first-class values
- real closures

differences:
- Lua is more verbose (begin...end vs {...})
- table constructor syntax is slightly different (but easier to read, IMO)
- any value can be a key in a table, not just numbers and strings
(it's great to index by any object, or even by a function/closure)
- real lexical scoping
- OOP is just a little syntax sugar, there's no predefined inheritance style.
- there's no array class (or constructor/prototype), every table can
be (efficiently) used as an array.
- coroutines
- very fast, very compact, very portable, very embeddable C implementation.
- VERY easy to extend with C modules
- LuaJIT

hum.... i think those are the biggest points.

-- 
Javier

Reply | Threaded
Open this post in threaded view
|

Re: LUA Vs Javascript

DracoBlue
Hello,

I am working with both right now, so I would just like to append to that (very complete list!), that I noticed that lua does not has anything comparable to javascript's exception handling and throwing.

Regards,
 Jan
[snip]

common points:
- really dynamic language
- all objects are hash tables
- you can access fields like obj.field, or obj[field]
- functions are first-class values
- real closures

differences:
- Lua is more verbose (begin...end vs {...})
- table constructor syntax is slightly different (but easier to read, IMO)
- any value can be a key in a table, not just numbers and strings
(it's great to index by any object, or even by a function/closure)
- real lexical scoping
- OOP is just a little syntax sugar, there's no predefined inheritance style.
- there's no array class (or constructor/prototype), every table can
be (efficiently) used as an array.
- coroutines
- very fast, very compact, very portable, very embeddable C implementation.
- VERY easy to extend with C modules
- LuaJIT
[/snip]


--

http://dracoblue.net


Reply | Threaded
Open this post in threaded view
|

Re: LUA Vs Javascript

Alex Queiroz
Hallo,

Jan SchÃtze wrote:
Hello,

I am working with both right now, so I would just like to append to that (very complete list!), that I noticed that lua does not has anything comparable to javascript's exception handling and throwing.


     What's the big difference between JS system and error/pcall/xpcall?

-alex
http://www.ventonegro.org/


Reply | Threaded
Open this post in threaded view
|

Re: LUA Vs Javascript

Ketmar Dark-2
On Fri, 27 Jun 2008 17:03:23 -0300
Alex Sandro Queiroz e Silva <[hidden email]> wrote:

>       What's the big difference between JS system and
> error/pcall/xpcall?
syntactic sugar.

Reply | Threaded
Open this post in threaded view
|

Re: LUA Vs Javascript

Wesley Smith
In reply to this post by DracoBlue
> I am working with both right now, so I would just like to append to that
> (very complete list!), that I noticed that lua does not has anything
> comparable to javascript's exception handling and throwing.

What about error and assert?  Also, much of the exception handling
happens on the C side.

wes

Reply | Threaded
Open this post in threaded view
|

Re: LUA Vs Javascript

Chris-41
In reply to this post by James Kimble
I think the main issue here is that Lua has no standard GUI system.
HTML + Javascript + browser gives you that.

As a programming languages Lua and Javascript are very similar in
concept but I think Lua is a whole lot cleaner and would make a better
Javascript than Javascript.

CR


On Fri, Jun 27, 2008 at 3:33 PM, James Kimble <[hidden email]> wrote:
>
> Not trying to start any kind of fire fight AT ALL. Just wanting to compare
> technologies. One I'm familiar with, the other completely new to.
>
> I'm in the process of assessing  various technologies for use on an embedded
> platform intended to operate as a control interface to something else
> (doesn't matter what here). We've got a local GUI on 1/4 VGA display that we
> want to duplicate (though improve the look of) as a web based GUI. My first
> thought was HTML with Javascript (Our boa web server doesn't seem to do much
> else). A developer suggested Lua as an alternative. I've looked through some
> of the documentation and played with it a little and it looks like a great
> little language. However I'm not really seeing any advantage to what I was
> planning to do with Javascript (Graphics and things that are more difficult
> with HTML).
>
> Can someone experienced with Lua please comment. I don't want to discourage
> a good new technology from entering into use in our device. I would welcome
> that if it makes sense. What I'm not sure of is, does it make sense?
>

Reply | Threaded
Open this post in threaded view
|

Re: LUA Vs Javascript

James Kimble
In reply to this post by Javier Guerra Giraldez
Javier Guerra wrote:
Lua and JavaScript have a lot in common.  (that's a little surprising,
especially for some like me, that absolutely love Lua and find
JavaScript unforgivably ugly :-)

common points:
- really dynamic language
- all objects are hash tables
- you can access fields like obj.field, or obj[field]
- functions are first-class values
- real closures

differences:
- Lua is more verbose (begin...end vs {...})
- table constructor syntax is slightly different (but easier to read, IMO)
- any value can be a key in a table, not just numbers and strings
(it's great to index by any object, or even by a function/closure)
- real lexical scoping
- OOP is just a little syntax sugar, there's no predefined inheritance style.
- there's no array class (or constructor/prototype), every table can
be (efficiently) used as an array.
- coroutines
- very fast, very compact, very portable, very embeddable C implementation.
- VERY easy to extend with C modules
- LuaJIT

hum.... i think those are the biggest points.
Thanks for the detailed response. It's just what I was looking for.

I have not worked, to any great degree, with Javascript. It just seemed a natural choice. Lua sounds like it has better structure to it's syntax and scoping (which is good) and that alone tends to make me want to go with it. My biggest concern is that there is a body of work out there in JS that can be reused easily that I'm sure doesn't exist for Lua because of it's newness. JS also has the advantage of having been around for a long time so browser support is a non-issue. Is browser support good for Lua? Is there room for concern there over JS?

I guess I'm trying to talk myself into Lua I just don't want to go with something so new I get burned by it. This is a mission critical project (yeah, I hate that term too) and our schedule is nuts (really nuts). I need to pick correctly the first time because I won't get a second chance.

Thanks again!

Reply | Threaded
Open this post in threaded view
|

Re: LUA Vs Javascript

Petite Abeille
In reply to this post by Chris-41

On Jun 27, 2008, at 10:08 PM, Chris wrote:

I think the main issue here is that Lua has no standard GUI system.
HTML + Javascript + browser gives you that.

Arguably one could use HTML + Javascript + browser on the client side and Lua on the server side.

FWIW, here is a pure Lua HTTP server implementation:

http://dev.alt.textdrive.com/browser/HTTP/HTTP.lua

--
PA.
http://alt.textdrive.com/nanoki/

Reply | Threaded
Open this post in threaded view
|

Re: LUA Vs Javascript

James Kimble
In reply to this post by Chris-41
Chris wrote:
I think the main issue here is that Lua has no standard GUI system.
HTML + Javascript + browser gives you that.

As a programming languages Lua and Javascript are very similar in
concept but I think Lua is a whole lot cleaner and would make a better
Javascript than Javascript.

CR

Now that IS a big deal. The biggest thing I need JS for is graphics. We are, after all, duplicating a local GUI as a Web interface. That's too bad....

Thanks for that insight.


Reply | Threaded
Open this post in threaded view
|

Re: LUA Vs Javascript

Petite Abeille-2-2
In reply to this post by James Kimble

On Jun 27, 2008, at 10:14 PM, James Kimble wrote:

Is browser support good for Lua? Is there room for concern there over JS?

Hmmm, err, well, like, there is no real Lua support in any mainstream browsers :))

Reply | Threaded
Open this post in threaded view
|

Re: LUA Vs Javascript

Javier Guerra Giraldez
In reply to this post by James Kimble
On Fri, Jun 27, 2008 at 3:14 PM, James Kimble <[hidden email]> wrote:
> My biggest concern is that there is a body of work out there in JS that can
> be reused easily that I'm sure doesn't exist for Lua because of it's
> newness. JS also has the advantage of having been around for a long time so
> browser support is a non-issue. Is browser support good for Lua? Is there
> room for concern there over JS?

Lua is not new. it's really mature and stable (arguably much more than
JavaScript, but that's a biased opinion).

JS is much more well-known, so you really have a lot of code to pick
and copy.  about said code's quality.... there are some good libraries
but not so many.

browser support for Lua? 0

for a server Lua is a great solution, also for the client, if you're
writing it (really easy to embed in C code).

if you want to program for an existing browser, go with JS

-- 
Javier

Reply | Threaded
Open this post in threaded view
|

Re: LUA Vs Javascript

James Kimble
Javier Guerra wrote:
Lua is not new. it's really mature and stable (arguably much more than
JavaScript, but that's a biased opinion).

JS is much more well-known, so you really have a lot of code to pick
and copy.  about said code's quality.... there are some good libraries
but not so many.

browser support for Lua? 0

for a server Lua is a great solution, also for the client, if you're
writing it (really easy to embed in C code).

if you want to program for an existing browser, go with JS

Yeah, that seems to be the consensus I'm coming to also (to use JS). Too bad. I will play with Lua some more though. It looks like a nice alternative to things like Perl and Ruby. Never hurts to add another tool to the tool box though.

Thanks to everyone that responded. This was a very enlightening discussion.

Reply | Threaded
Open this post in threaded view
|

Re: LUA Vs Javascript

DracoBlue
In reply to this post by Alex Queiroz
Hey,

the difference is (in javascript):
try {
   // try something strange which usually works
} catch (e) {
   // on exception
}

there it actually does not matter where the exception is thrown, you just need to find a place where the try+catch handles it. So its' pretty much, like php5/c#/java/delphi manages exceptions and gives you quite simple possibility to handle the exceptions when it occurs and where you want to handle it - with the opportunity to continue the script after the exception is handled. I wasn't able to create a quite similar and simple approach in lua, yet. It would be cool, if that would be possible with error+pcall somehow!

Except that - which is actually just quite important for widely splitted and modularized software - I see the possibilities of lua (considering speed which is/was way better then current javascript implementations) are really worth to check and evaluate it as opportunity.

Regards,
 Jan

Alex Sandro Queiroz e Silva wrote:
What's the big difference between JS system and error/pcall/xpcall?


--

http://dracoblue.net


Reply | Threaded
Open this post in threaded view
|

Re: LUA Vs Javascript

Alex Queiroz
Hallo,

Jan SchÃtze wrote:
Hey,

the difference is (in javascript):
try {
   // try something strange which usually works
} catch (e) {
   // on exception
}

there it actually does not matter where the exception is thrown, you just need to find a place where the try+catch handles it. So its' pretty much, like php5/c#/java/delphi manages exceptions and gives you quite simple possibility to handle the exceptions when it occurs and where you want to handle it - with the opportunity to continue the script after the exception is handled. I wasn't able to create a quite similar and simple approach in lua, yet. It would be cool, if that would be possible with error+pcall somehow!


I didn't think you were talking about syntactic differences. To write something like that you'd need MetaLua.

-alex
http://www.ventonegro.org/


Reply | Threaded
Open this post in threaded view
|

Re: LUA Vs Javascript

Tony Finch
In reply to this post by Javier Guerra Giraldez
On Fri, 27 Jun 2008, Javier Guerra wrote:
>
> differences:
> - real lexical scoping
> - OOP is just a little syntax sugar, there's no predefined inheritance style.

Those are actually both similarities, though JS has a more conventional
OOpy programming style, partly because of the standard libraries.

Tony.
-- 
f.anthony.n.finch  <[hidden email]>  http://dotat.at/
ROCKALL MALIN: CYCLONIC BECOMING SOUTHWESTERLY 5 OR 6, OCCASIONALLY 7 AT
FIRST. MODERATE OR ROUGH, OCCASIONALLY VERY ROUGH. RAIN OR THUNDERY SHOWERS.
MODERATE OR GOOD, OCCASIONALLY POOR.

Reply | Threaded
Open this post in threaded view
|

Re: LUA Vs Javascript

Petite Abeille
In reply to this post by DracoBlue

On Jun 27, 2008, at 10:48 PM, Jan SchÃtze wrote:

It would be cool, if that would be possible with error+pcall somehow!

Syntax sugar aside, it's rather straightforward to roll your own try/ catch implementation according to your needs/circumstances, e.g.:

local function try( aFunction, ... )
    local someArguments = { ... }
    local aLength = select( "#", ... )

    return function( catch )
local someResults = { pcall( aFunction, unpack( someArguments, 1, aLength ) ) }
        local aStatus = someResults[ 1 ]

        if aStatus == true then
            return unpack( someResults, 2, table.maxn( someResults ) )
        else
            local anException = someResults[ 2 ]

            if catch ~= nil then
return catch( anException, aFunction, unpack( someArguments, 1, aLength ) )
            end

            return nil, anException
        end
    end
end

Usage example:

local function catch( anException, ... )
    print( anException, ... )
end

local function Test( aValue )
    error( 'panic! ' .. aValue )
end

try( Test, 'hello' )( catch )

print( 'Done' )

Reply | Threaded
Open this post in threaded view
|

Re: LUA Vs Javascript

Javier Guerra Giraldez
In reply to this post by Tony Finch
On Fri, Jun 27, 2008 at 4:17 PM, Tony Finch <[hidden email]> wrote:
> On Fri, 27 Jun 2008, Javier Guerra wrote:
>>
>> differences:
>> - real lexical scoping
>> - OOP is just a little syntax sugar, there's no predefined inheritance style.
>
> Those are actually both similarities, though JS has a more conventional
> OOpy programming style, partly because of the standard libraries.

??

JS doens't have lexical scoping, just two-level scopes. may i had the
terminology wrong and it could be called 2-level lexical scope, while
Lua is full block based lexical scoping.

and OOP... in JS there are lots of arbitrary 'features' built into the
language, not only on the libraries, and not simply as syntax sugar.

the 'new' keyword makes 'constructor' behaviour for functions, the
'prototype' magic reference, making functions and other things into
objects, magically transforming a function into a closure that grabs
the 'object' when you reference it out of the object, the inconsistent
meanings of 'this'... all these are in the language, not everybody
likes them, but you can't fight them if you happen to prefer a more
'pure' prototype based inheritance, or even a non-inheritance OOP
design (like me ;-)

in Lua the only deference to OOP is the obj:method(...) =>
obj.method(obj,...) sugar.  everything else is user-definable.

-- 
Javier

Reply | Threaded
Open this post in threaded view
|

Re: LUA Vs Javascript

troels knak-nielsen
A couple of corrections:

On Fri, Jun 27, 2008 at 9:56 PM, Javier Guerra <[hidden email]> wrote:
> differences:
> - OOP is just a little syntax sugar, there's no predefined inheritance style.

Neither is there in Javascript. They are both prototype-based languages.

On Fri, Jun 27, 2008 at 11:34 PM, Javier Guerra <[hidden email]> wrote:
> JS doens't have lexical scoping, just two-level scopes. may i had the
> terminology wrong and it could be called 2-level lexical scope, while
> Lua is full block based lexical scoping.

Javascript has lexical scope. It doesn't have a package system though.

--
troels

Reply | Threaded
Open this post in threaded view
|

Re: LUA Vs Javascript

Stephen Kellett
In reply to this post by Javier Guerra Giraldez


On Fri, Jun 27, 2008 at 2:33 PM, James Kimble <[hidden email]> wrote:
Not trying to start any kind of fire fight AT ALL. Just wanting to compare
technologies. One I'm familiar with, the other completely new to.

I'd like to provide a view from that of a software tool maker. This view is based on our experience providing tools to users of Lua and the feedback from those users.

I prefer Lua to JS for most things, but one thing JS (and Ruby and Python, etc) does better is that in JS you can ask an object what its type is and get a human readable string that makes sense ("String", "Weeble", "Mouse", NASDAQPrice", etc).

In Lua you can only get a meaningful type name *IF* someone has thought to setup the appropriate data. If they haven't set that up, you get nothing.

For most things this is not important, but its very important if you are writing a debugging/profiling tool. Its important because:
a) We want the users of our tool to be able to have this information
b) The users of our tools want this information and *don't understand why it isn't available* from the tool, even though they are intimately familiar with the language.

Case in point: I asked about this many months ago after getting a request from the Abode Lightroom team for the type information. I said we didn't know how to do it. So we asked on this mailing list. We got some helpful responses (thank you, guys). But even after implementing the suggested methods for getting the type information on 40% of the various objects displayed in the memory allocation browser had meaningful types, the rest had type names that we synthesized from the method/filename/line number information.

Some of you will thing this is a minor issue. If you want Lua to be mainstream, things like this need to be addressed.

Yes, Lua is a great language. But finding the type of an object sucks. Most languages provide the type by default. Lua does not. You only get the type if the type implementor thought enough to do provide it for you.

Stephen


1234