Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
bugfix for lua.org demo page
local write,D,L,select,tostring,ipairs,concat,execute,sub,gsub=io.write,{},8192,select,tostring,ipairs,table.concat,os.execute,string.sub,string.gsub
local T,E,I
T=io.read"*a"
T=string.match(T,"=(.-)$") or ""
T=gsub(T,"+"," ")
T=gsub(T,"%%(%x%x)",function (x) return string.char(tonumber(x,16)) end)
T=gsub(T,"^%s*=%s*","return ")
write(sub(T,1,L))
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.getfenv=getfenv
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.loaded.io=io
package.loaded.package=nil
package=nil
require=nil
function write(...)
for _,v in ipairs{...} do
v=sub(v,1,L)
D[#D+1]=v
L=L-#v
end
end
T,E=loadstring(T,"=input")
if not T then
write(E) E="failed to compile" I="alert"
else
T=(function (...) return {select('#',...),...} end)(pcall(T))
if not T[2] then
write(T[3]) E="failed to run" I="alert"
else
E="ran successfully" I="ok"
for i=3,T[1]+1 do write(tostring(T[i]),"\t") end
end
end
write[[</TEXTAREA><P>]]
write('<IMG SRC="images/',I,'.png" ALIGN="absbottom">\n')
write("Your program ",E,".")
write("<!-- ")
execute("printf '%s\\n' '"..gsub(concat(D),"'","'\\''").."' >&3")
#!/bin/sh
LUA=/home/lhf/websites/lua.org/www/bin/lua
LOG=log
ECHO="/bin/echo -E"
cat <<EOF
Content-type: text/html
EOF
date "+%n@ %c $REMOTE_HOST $REQUEST_METHOD $HTTP_REFERER" >> $LOG
if [ "$REQUEST_METHOD" = "GET" ]
then
if [ "$QUERY_STRING" = "" ]
then
exec cat demo.html
else
$ECHO "$QUERY_STRING" >> $LOG
F=`basename -- "$QUERY_STRING"`.lua
sed '/TEXTAREA/q' demo.html
$ECHO "-- $F"
(cat -- "$F" 2>&1)
sed '1,/TEXTAREA/d' demo.html
fi
else
sed '/TEXTAREA/q' demo.html
tee -a $LOG | (ulimit -t 1 ; { res=$($LUA demo.lua 3>&1 >&4 2>&4 4>&-); } 4>&1 ; printf "%s\n" "$res")
cat <<EOF
</TEXTAREA><P><IMG SRC="images/alert.png" ALIGN="absbottom">
Your program was aborted.<!-- -->
<P>
<HR>
<SMALL>
EOF
$LUA -v 2>&1
cat <<EOF
</SMALL>
</BODY>
</HTML>
EOF
echo '' >> $LOG
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.