[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Thought experiment: what would you remove from Lua
- From: Albert Chan <albertmcchan@...>
- Date: Wed, 1 Aug 2018 07:12:33 -0400
> * 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