A simple arithmetic function.

Share your scripts and packages with other Mudlet users.
Post Reply
hempa
Posts: 48
Joined: Sat Jan 02, 2010 1:07 pm

A simple arithmetic function.

Post by hempa »

I found a useful function that can take any basic arithmetic expression and evaluate it.

Syntax is: doMath( expression, message_if_true )
Expression must be a valid math expression. You can use +-*/^ as well as ( ) as in normal math.
If message_if_true is true, it will display "<expression> = <evaluated expression>", otherwise it will return the result of the evaluation.

Function was found at Rosettacode.org

Requires LPeg. For convenience, I have attached the dll for windows users, which I found in the Lua For Windows installation.
lpeg.7z
LPeg dll, 7zipped
(14.94 KiB) Downloaded 426 times
doMath.xml
the doMath function, as a script.
(2.05 KiB) Downloaded 412 times
No claim made for making these, I just added the math.pow function to the thing :) Hope it's of use to you.

hempa
Posts: 48
Joined: Sat Jan 02, 2010 1:07 pm

Re: A simple arithmetic function.

Post by hempa »

Forgot to say, drop the unzipped .dll in the mudlet install directory before you try to run this. If you have problems unzipping, use jeans with buttons :twisted: Or go to the 7Zip webpage to get a very good zip utility. Free!

User avatar
Vadi
Posts: 5042
Joined: Sat Mar 14, 2009 3:13 pm

Re: A simple arithmetic function.

Post by Vadi »

I highly discourage posting scripts that are useless without modifications to Mudlets installation.

If you want to make it useful, convert it to lrexlib. Otherwise it's useless for a lot for all Mac and Linux users.

hempa
Posts: 48
Joined: Sat Jan 02, 2010 1:07 pm

Re: A simple arithmetic function.

Post by hempa »

I did find a simpler way of doing this that uses the Lua system itself. It's not as fast if you should be doing bulk calculations, but should be enough for alias use.
arithmetic.xml
(409 Bytes) Downloaded 552 times

Post Reply