Javascript vs. Lua (23)

1 Name: #!usr/bin/anon 2006-01-05 22:36 ID:47J/VvAI

I don't know much about Lua, but it looks a lot like Javascript. Is the only advantage that Lua has is the small interpreter? DISCUSS!

2 Name: #!usr/bin/anon 2006-01-05 23:06 ID:kdUZ8Jcm

I don't know JavaScript (beyond the basics), but I was not aware there was much similarity. They certainly don't look the same; Lua's not a curly-bracket language.

Lua is embeddable, portable and fast. It's designed to be picked up as a second language, so it's simple and easy to learn. It can be programmed in an imperative, functional, or, to a limited extent, object-oriented style. Does JavaScript share these attributes (which ones)?

3 Name: !WAHa.06x36 2006-01-06 01:59 ID:V43PLCsl

Javascript is a modern scripting language, and pretty much all of those are to some extent imperative/functional/OO hybrids.

Lua's popular as a scripting language because it is easily embeddable, I guess. I tried looking into it but I never got around to finding an actual use for it... Personally, I'd really like an easily embeddable and fast JavaScript engine.

4 Name: #!usr/bin/anon 2006-01-06 03:38 ID:kdUZ8Jcm

>>3
Do you prefer JavaScript to Lua for any particular reason, other than familiarity?

5 Name: #!usr/bin/anon 2006-01-06 10:54 ID:c2Rp68pb

>>I tried looking into it but I never got around to finding an actual use for it

The only time i've ever seen it used is by people moding the WoW UI.

6 Name: !WAHa.06x36 2006-01-06 13:28 ID:hCZx3bgP

>>4

Mostly familiarity. Plus, it is a very powerful and clean language.

7 Name: #!usr/bin/anon 2006-01-06 17:55 ID:kdUZ8Jcm

>>6
I never said it wasn't powerful or clean, but Lua is those things too.

Perhaps I should learn JavaScript so that one of us can actually compare the two. What's a decent standalone interpreter?

8 Name: !WAHa.06x36 2006-01-06 21:22 ID:tTui9Y6R

I don't know of one. There is probably one, but since the standard doesn't specify much in the way of a standard library for accessing an OS outside of a web browser, it'd be of limited usefulness.

I've been thinking that it'd be sort of neat to be able to use Javascript for server-side CGI, though. You could even include a full DOM for building pages with, plus it'd make communicating with client-side Javascript code somewhat easier.

9 Name: #!usr/bin/anon 2006-01-06 23:19 ID:kdUZ8Jcm

Well, crud. Is there an implementation suitable for embedding in applications in general (not just web browsers)? If so, it would be pretty easy to make a standalone implementation with a basic library using that -- that's how the Lua interpreter is designed.

10 Name: #!usr/bin/anon 2006-01-07 00:21 ID:47J/VvAI

microsoft has wscript.exe and cscript.exe which are standalone jscript (lol) interpreters - they're somewhat oriented towards automated maintenance, as they don't have any builtin messagebox or console output functions, but they do have builtin file i/o functions.

as for embedding JS, i looked around and the only implementation i would trust is mozilla's SpiderMonkey, which is a bit verbose but there seem to be some tools for autogenerating the C<->JS glue code (google jsgen).

11 Name: #!usr/bin/anon 2006-01-07 02:02 ID:Heaven

Hmm, that doesn't sound promising. I guess what's killing JavaScript then is the lack of quality implementations. Not counting the web, where it has a monopoly, of course.

12 Name: dmpk2k!hinhT6kz2E 2006-01-07 05:43 ID:Heaven

If they're similar, maybe they should replace javascript with lua? I doubt any implementation of javascript will ever be as fast as lua5, which is too bad, because the whole idea of web apps would be more feasible if it had fast underpinnings. :(

I'm only half joking.

13 Name: #!usr/bin/anon 2006-01-07 10:35 ID:ag77bCPb

http://cataclysm.cx/Amber

"Amber is a "runtime environment" or "host" for the Javascript language. It provides a Javascript interpreter and a set of add-on packages (called "modules") to provide access to various system services (files, sockets, threads, etc) - all from a single binary which can be run from the command line."

14 Name: #!/usr/bin/anon 2006-01-17 07:06 ID:47J/VvAI

Lua apparently has support for coroutines, which is pretty cool.

15 Name: #!/usr/bin/anon 2006-01-17 10:21 ID:Heaven

>>14
whorouwhats?

16 Name: #!/usr/bin/anon 2006-01-17 16:00 ID:kdUZ8Jcm

Coroutines are a generalization of subroutines, allowing one routine to consume as input the output of another routine. Imagine that in C you could write:

int function(void)
{
int i;
for (i = 0; i < 10; i++)
return i;
}

and successive calls to the function would return 0 through 9. That C code doesn't really work, but this is what coroutines let you do. See also:

http://www.chiark.greenend.org.uk/~sgtatham/coroutines.html
http://www.lua.org/manual/5.0/manual.html#2.10
http://www.lua.org/pil/9.html

Another cool language supporting coroutines is Icon, http://www.cs.arizona.edu/icon/. Lua's coroutines were inspired by Icon, I think.

17 Name: #!/usr/bin/anon 2006-01-18 09:20 ID:Heaven

>>16
Oh yeah, now I remember reading about those somewhere (probably this board somewhere, lol). Didn't recognise the name, though. Thanks.

18 Name: #!/usr/bin/anon 2006-02-07 00:04 ID:yNrwn+lb

>>16
This is exactly like Python's yield statement which creates generators which can be iterated or called .next() . An awesome feature BTW, you can do many great things with this, as well as simplify some algorithms by separating them in several functions that take care of a little thing each.

19 Name: #!/usr/bin/anon 2006-02-21 04:09 ID:dBFyrEhb

Isn't that a generator? A coroutine is where you have some number of functions A,B... and they can jump inside each other arbitrarily, like this:
A
|
|-jump!-B

    |
|
|

|-------+ #back to A
|
|

In ye olden days coroutines were used to make lightweight thread-style code, e.g. A is the user (gets input), and B is an AI player. They are still good for making lightweight threads withouot relying on external libraries or loljava.

Incidentally. python wins:
def func():

i=0
while i<10:
yield i
i+=1

(or, since we aren't passing any arguments, this works too:)
(i for in in range(10))
or, come to think of it, xrange(10) works too, but that doesn't explain anything.

20 Name: #!/usr/bin/anon 2006-02-23 02:18 ID:kdUZ8Jcm

>>19

The exposition in >>16 is cribbed from Simon Tatham's article. I think his point is that coroutines are a way to implement generators, though they certainly have other uses.

21 Name: #!/usr/bin/anonymous : 2006-03-24 16:52 ID:GHy3uv5y

22 Name: #!/usr/bin/anonymous : 2006-03-25 22:54 ID:Heaven

By the way, Lua's C API is really fucking annoying. It takes like eight calls to do anything.

23 Name: #!/usr/bin/anonymous : 2006-05-02 15:34 ID:Heaven

Back to javascript:
when i looked into doing programming on the ipaq PDA,
someone suggested coding in JavaScript inside the IE web browser. That would give you some GUI widgets.

Also, one student wrote a wrapper around the jscript interpreter library and created an API from his jscript code to the regular windows API. I just tried to locate the forum where I originally read that, but no luck. Sorry. But I remember he showed his source code, and it was easier and smaller than you might think.

This thread has been closed. You cannot post in this thread any longer.