Skip to content

Commit 6f3e571

Browse files
committed
Added some base conversions
1 parent 4eb9166 commit 6f3e571

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

plugins/Calculator.xml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
language="Lua"
1010
purpose="Provides a simple calculator"
1111
date_written="2010-08-25 14:55:13"
12+
date_modified="2014-09-27 10:09:00"
1213
requires="4.50"
13-
version="1.0"
14+
version="1.1"
1415
>
1516
<description trim="y">
1617
<![CDATA[
@@ -30,6 +31,13 @@ eg.
3031
= match ("fruit", "u")
3132
= shl (4, 4)
3233
34+
In addition, you can use hex, oct, bin functions to convert to those bases for printing.
35+
36+
eg.
37+
38+
= hex (1234)
39+
= oct (5678)
40+
= bin (15)
3341
]]>
3442
</description>
3543

@@ -46,6 +54,11 @@ eg.
4654
sequence="100"
4755
>
4856
<send>
57+
-- useful number conversions
58+
bit.hex = function (num) return bit.tostring (num, 16) end
59+
bit.oct = function (num) return bit.tostring (num, 8) end
60+
bit.bin = function (num) return bit.tostring (num, 2) end
61+
4962
print ("%1 =", setfenv (assert (loadstring "return %1"), setmetatable ({},
5063
{__index = function (_, n) return math [n] or bit [n] or string [n] or utils [n] or world [n] end}) ) () )
5164
</send>

0 commit comments

Comments
 (0)