Code: Select all
function calc(exp)
return assert(loadstring("return "..exp))() or 0
end
The advantages to this over the other function available for the same thing:
* It doesn't require a library
* It's cross-platform
* It's a one liner
I'm using it in an alias, like so:
Pattern: ^bc (.*)$
Send: echo("Math: "..calc(matches[2]))
but you could probably do a lot more with it.