Of Lua, Quines and mod_wombat

I've been playing around with Lua (my current favourite dynamic language) in two areas of late: Quines (programs who print their own source code when run), and mod_wombat - a Lua module for Apache2.

First off, a quine:

s="s=%qprint(s:format(s))"print(s:format(s))

That one is a port of a classic C quine from Wikipedia over to Lua:
main() { char *s="main() { char *s=%c%s%c; printf(s,34,s,34); }"; printf(s,34,s,34); }

Of course, if you're going for shortest quine possible, then it would have to be this one:

 

Yes, that is an empty (zero byte) file. The Lua interpreter will happily execute a zero byte source file, and will output nothing while doing so, which matches the source file (again, a duplicate of a C one from 1994; http://www0.us.ioccc.org/1994/smr.hint)

Moving on to mod_wombat, I've set up a virtual private server and installed mod_wombat on it. This allows me to make scripted web pages using Lua instead of PHP - something which pleases me greatly. mod_wombat needs work (and a website, etc.), but it is getting some love from Google's Summer of Code, so perhaps one day Lua will be a common language for web development. I'll be posting a link to a mod_wombat powered blog about mod_wombat sometime soon (hosted on the aforementioned VPS), so stay tuned.

Comments

Quines

Woo! Quines are fun \o/
Here is another one using loadstring():
s = [[print('s = ['..'['..s..']'..']\nloadstring(s)()')]]
loadstring(s)()
..and one using only print():
function f(s)
print(s..'['..'[')
print(s..']'..']')
print('f(s)')
end
s = [[
function f(s)
print(s..'['..'[')
print(s..']'..']')
print('f(s)')
end
s = ]]
f(s)
..and of course any concatenation of different quines is again a longer quine in Lua (if you're not considering a bossible beginning #!/usr/env lua -line)

nice

Nice , this is the first time I heard of this language , but this looks interesting I do more research on it^^

-Dino Delellis

Have You Posted The Link

Hi Peter,

Sorry to be a pain. Have you posted the link to mod_wombat yet?

I know this is an old post, I found it while searching language. If you have posted it else where can yo let me know? Or leave the link here in the comments.

All The Best
Costa

Tralala

Well done, but what is all that chnia spam doing here ? o_O

PHP vs. Lua

Quick question - why do you prefer Lua over PHP (sorry if that's a question deserving a 4 page response)? Is Lua code cleaner? Is Lua common enough to find a programmer for it -

We've been having some problems with PHP (not sure if it's just the developers) and have been looking into using different languages.

mod_wombat

Hi Corsix,

I have the question (I try to use mod_wombat in my dedicated server): Did you have any problems with mod_wombat when run lua script? Is it stable solution - apache + mod_wombat + mysql, have you any improvements for that?

thx,

Hibernaculus

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <span>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <brainfuck>, <c>, <cpp>, <haskell>, <lua>, <php>.

More information about formatting options