As an example of the advantages of lua, the old unrpm-- in awk was:

#!/bin/sh
awk 'BEGIN{
RS=" "
"filesize '$1'"|getline SZ
for(SK=-1;SK<SZ;SK++){
 LR=TR
 "tomshexd -r<'$1'"|getline TR
 if(LR TR=="1f8b"){
  CK=system("dd if='$1' bs=1 skip="SK" 2>/dev/null|gzip -t")
  if(CK==0){
   system("dd if='$1' bs=1 skip="SK" 2>/dev/null|gzip -d|cpio -iuvmd")
   break
}}}}'

In lua it is:

#!/usr/bin/lua -f
if getargs()[3] then readfrom(getargs()[3]) end
while 1 do
        b=read(1)
        if not b then break end
        if b=="\31" then
                b=read(1)
                if not b or b=="\139" then break end
        end
end
if not b then
        _ALERT("ERROR\n")
        exit(-1)
end
writeto("|gzip -d|cpio -iuvmd")
write("\31\139")
buf = read(8192)
while buf do
        write(buf)
        buf = read(8192)
end

granted, it has gone from 297 bytes to 351 bytes, but at a 120x
performance boost!

-Tom

Reply via email to