News for hackers. Stuff that matters.
Re:Node.js Versus LUA "Hello World" HTTP Server Showdown by silentbicycle on Wednesday October 13, 2010 @10:57AM (#1787304)
5.0, not 4.0 - you're right, thanks. Missed the edit window. :/

And yes, the 5.2 environment handling sounds like an improvement to me as well.

Re:Node.js Versus LUA "Hello World" HTTP Server Showdown by pygy_ on Wednesday October 13, 2010 @01:17PM (#1787958)
I liked setfenv() for its versatility.

I implemented a toy markaby [1] clone in Lua using it.

    tpl = html(function()
        head(function() --> tag names should be non-locals. They will be rebound at runtime.
            title "Barbazor"
            link {rel = "stylesheet", type = "text/css", href = "style.css"}
        end
        body(function()
            h1 {"Big title"; id = "title"}
            div {class = "foo"; function()
                for i=1,5 do
                    p( "counting: " .. i )
                end
            end}
        end
    end
    
    render( tpl ) --> returns clean, well indented HTML.
I don't think it can be done with the new environment system without reimplementing setfenv. You could achieve the same effect by passing an explicit param to anonymous functions, but it would look worse IMO.

This example also highlights a weakness in the language syntax: lambdas are ugly. Functions are first-class, semantically, but not syntactically, which is sad.

[1] http://markaby.rubyforge.org/ , just in case ;-)

Re:Node.js Versus LUA "Hello World" HTTP Server Showdown by silentbicycle on Wednesday October 13, 2010 @01:30PM (#1788022)
Hah. I did exactly the same thing. I usually use discount instead, though. To my understanding, it'd work to set _ENV's metatable's __index to a table w/ HTML tag generators. I've read about _ENV but haven't actually used 5.2-work4 yet. (I started using 5.2-work2 but they went and changed it again, so now I'm waiting until it's a sure thing.)

I agree that the syntax for first class funs could be more concise, but that's true of any language that requires a "return" keyword (i.e., is statement-based rather than expression-based). I think "fun x -> x + 1 end" would be better, but maybe that's just the OCaml talking.

Re:Node.js Versus LUA "Hello World" HTTP Server Showdown by pygy_ on Wednesday October 13, 2010 @03:30PM (#1788519)
Using _ENV would not be that simple.

    * The library and template files may have different _ENVs. 
    * The _ENV of the tempalte file could already have an __index.
You'd have to add something like `_ENV = luhtml.makeENV(_ENV)` before your template definitions to take care of this.

The only way to have a clean template file would be to emulate setfenv using the debug library.

--

My main gripe with the current syntax is that, when scanning the code, function declarations and invocations are too similar.

I'd like to have somthing like

    :[x] print(x); -> x+1 end 
or

    :]x[ -> x+1 ]
Both are unambiguous, and would allow to pass a lambda to a function requiring a single argument without parenthesis, like you can already with strings and table litterals.

    somefun :]x[ dosomething( x ) ]
I prefer the second syntax because of the initial happy smiley, although it the reversed brackets are alien and would cause an uproar if they were to be added in any popular language.

--

At last, what is discount?

Re:Node.js Versus LUA "Hello World" HTTP Server Showdown by silentbicycle on Wednesday October 13, 2010 @03:41PM (#1788559)
Discount (http://www.pell.portland.or.us/~orc/Code/discount/) is a very fast, C-based implementation of Markdown (http://daringfireball.net/projects/markdown/).

I have a Lua wrapper for it, but just noticed that I don't have it on my github page. I'll post it soonish. Somebody else has a Lua wrapper for an older version of discount, but includes the discount source in it (!), and it's been updated due to security-related bugs, so that's out.

Talking about reversed brackets, look at J (http://www.jsoftware.com/). The only language I've seen that uses ], [, {, and } as unpaired operators. Pretty serious heresy. Cool language, though.

Re:Node.js Versus LUA "Hello World" HTTP Server Showdown by pygy_ on Wednesday October 13, 2010 @04:17PM (#1788697)
Thanks for all that :)