lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


> Any chance to see this open-source?

Sure, the main Lua program is attached. Sorry, there are no comments in
the program. It is just a quick proof-of-concept hack.

There are two other files, the HTML that is shown when you visit
http://www.lua.org/cgi-bin/demo and a simple CGI script that decides
what to show and runs Lua if there's a Lua program in the text box.

> [1] : http://tryruby.hobix.com/

Yes, this is very nice. But it'd be a lot of work to do it for Lua,
messing up with Javascript etc. Let's see how the current demo does for
a while.
local T,E
T=io.read"*a"
T=string.match(T,"=(.-)$") or ""
T=string.gsub(T,"+"," ")
T=string.gsub(T,"%%(%x%x)",function (x) return string.char(tonumber(x,16)) end)

local write=io.write

write(T)
write[[</TEXTAREA>
<P>
<INPUT TYPE="submit" VALUE="Run">
<INPUT TYPE="button" VALUE="Clear" onclick="this.form.elements['input'].value=''">
<INPUT TYPE="reset" VALUE="Original">
</FORM>
<P>

<H2>Output</H2>
<TEXTAREA ROWS="8" COLS="80">
]]
io.flush()

arg=nil
debug.debug=nil
debug.getregistry=nil
dofile=nil
io={write=io.write}
loadfile=nil
os.execute=nil
os.getenv=nil
os.remove=nil
os.rename=nil
os.tmpname=nil
package=nil
require=nil

local I="alert"
T,E=loadstring(T,"=input")
if not T then
	write(E) E="failed to compile"
else
	--T,E=xpcall(T,debug.traceback)
	T,E=pcall(T)
	if not T then
		write(E) E="failed to run"
	else
		E="ran successfully" I="ok"
	end
end
write[[</TEXTAREA><P>]]
write('<IMG SRC="images/',I,'.png" ALIGN="absbottom">\n')
write("Your program ",E,".")
write("<!-- ")