lua-users home
lua-l archive

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


* On Mon Jun 20 06:54:51 +0200 2011, PROXiCiDE wrote:
 
> Is it possible to crunch these repeatable statements in Lua? with out the
> rewrite "IF" statements etc.. maybe inside Array/Table checking etc
> 
>       if(xArg.exp==">") then
>         if(what > number) then
>           print(name,daysTotal)
>         end
>       end
>       
>       if(xArg.exp==">=") then
>         if(what >= number) then
>           print(name,daysTotal)
>         end
>       end
>       
>       if(xArg.exp=="<") then
>         if(what < number) then
>           print(name,daysTotal)
>         end
>       end
>       
>       if(xArg.exp=="<=") then
>         if(what <= number) then
>           print(name,daysTotal)
>         end
>       end
>       
>       if(xArg.exp=="=") then
>         if(what == number) then
>           print(name,daysTotal)
>         end
>       end

You could use loadstring() to generate a piece of lua code on the fly to
do the check, something like (untested):

  if loadstring('return '.. what .. xArg.exp .. number)() then
     print(name,daysTotal)
  end

-- 
:wq
^X^Cy^K^X^C^C^C^C