lua-users home
lua-l archive

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


> * string.reverse() (anyone used it?)

My script calc.lua used it to search for last ";"

Calc a=3; b=7; c=10; b*b - 4*a*c 

=> lua calc.lua "a=3; b=7; c=10; b*b - 4*a*c"
=> -71

 t= s:reverse():find(';', 2, 'plain')    -- locate last ;

if t then    -- multi-statements detected
  s = "function()" .. s:sub(1, -t) ..
         " return " .. s:sub(-t+1) ..
         " end)()" 
end
print( loadstring("return " .. s)() )    -- evaluate