Lua Quine!

So as you might or might not have known, a quine program is a program that outputs it’s own source code. Since this is a lua scripting thread, I thought you guys might be interested in the lua quine code!

(deprecated)
[lua]
y = [[ print(“y = [[” … y … “]]
dostring(y)”) ]]
dostring(y)
[/lua]

(working)
[lua]
s=[[io.write(‘s=[’,’[’,s,’]’,’];’,s)]];io.write(‘s=[’,’[’,s,’]’,’];’,s)
[/lua]

Tada! Try it out yourself at http://www.lua.org/cgi-bin/demo

Or here’s the hypothetical version of the quine code:

[lua]
s=print(s=print(s=print(s=print( --It goes on infinitely
[/lua]

To do this properly you’d do something like this.

print(file.Read(debug.getinfo(1).short_src))

Not what you posted.

[editline].[/editline]

Oh wait I see what you’re doing. Took a couple of reads to understand what was happening.

Argh! It’s deprecated from old lua syntax! Just tried it at http://www.lua.org/cgi-bin/demo, will upload a working one soon.

[editline]9th February 2011[/editline]

Ninja’d.

Keep in mind this doesn’t apply to Gmod lua specifically, just lua by itself. Try it out at the link above

[editline]9th February 2011[/editline]

Yes! Just tried out this and it works fine!

[lua]
s=[[io.write(‘s=[’,’[’,s,’]’,’];’,s)]];io.write(‘s=[’,’[’,s,’]’,’];’,s)
[/lua]

[editline]9th February 2011[/editline]

It looks odd, but It’s just defining a variable whilst running the write function with the same variable concatenated within a string.

Neat. Pretty useless, but still neat.

:v:

I have a shorter one! :v:

[lua]input:1: ‘<name>’ expected near ‘1’[/lua]

[editline]9th February 2011[/editline]

Ok, that was stupid, sorry for that. :saddowns:
Never tried to write quines, but those things look pretty fun to do when you’re bored.

Nah, these guys have the shortest one, albeit in C: (International Obfuscated C Code Contest)

:v:

Hahaha, now that’s clever. :v:

Empty files are not quines, even if they technically print out their “source code”, because there is no actual code in that case.

[editline]9th February 2011[/editline]

There’s even a language that prints out “Empty files are not quines.” when you try that :v:

:v: