|
FishyBug Newbie
Joined: 10 Jan 2008 Posts: 3
|
Posted: Thu Jan 10, 2008 2:50 pm
cMud and exponents. |
Hi,
I am trying to get exponents to work in cMud.
I cannot get #SHOW {x^y} to work and can't find a function for it. Am I missing something?
Thanks |
|
|
|
Dharkael Enchanter
Joined: 05 Mar 2003 Posts: 593 Location: Canada
|
Posted: Thu Jan 10, 2008 5:43 pm |
I dont think there's a built in way in CMUD.
I wrote a quick function to take advantage of the lua library to get it done.
Code: |
<func name="math" language="Lua" id="32">
<value>if zs.numparam == 0 then return nil end
local func = zs.param(1)
if type(math[func]) ~= "function" then return nil end
local arg = {}
for i=2,zs.numparam do
table.insert(arg,tonumber(zs.param(i)))
end
return math[func](unpack(arg))
</value>
</func> |
It's just a wrapper to the Lua math library.
A description of the functions available can be found here
To use it you would do something like.
#echo @math("pow",2,4)
It would then echo 16
I had it return 'nil' if you messed up but you could just as easily change that to return an empty string or to raise an exception |
|
_________________ -Dharkael-
"No matter how subtle the wizard, a knife between the shoulder blades will seriously cramp his style." |
|
|
|
Taz GURU
Joined: 28 Sep 2000 Posts: 1395 Location: United Kingdom
|
Posted: Thu Jan 10, 2008 6:10 pm |
Impressive!
|
|
_________________ Taz :) |
|
|
|
|
|