Lua: improve with Lua performance practices

eliminate global accesses
use a[#t+1] = a rather than table.insert for push_back
print breaks tracing on LuaJIT, use io.stdout
minor typo fix