MAcalc Pro Programming
MAcalc Pro functionality can be expanded with additional function libraries.
Each library can have up to 33 new functions each assigned
to it's own key in the calculator keypad.
Functions are
written in plain text files and you can use MAcalc's own
editor or a PC or Mac to edit new functions and transfer
them to MAcalc.
Libraries are saved in
/CustomFunctions/yourlibraryfolder. In the folder, a
file named customfuncs.plist holds information for
each key. Functions for each key are saved on separate
files.
customfuncs.plist file is created my
MAcalc when you use the builtin text editor to define new
functions. If you want to write your funtions on your PC/Mac
and transfer them to MAcalc, you have to create a
customfuncs.plist file yourself
Programming overview
MAcalc functions use a simple procedural syntax and are interpreted by a builtin "Lua" engine.
Single argument function
function f1(x)
return x + 1
end
function f2(x)
return x + 2
end
function main(x)
if (x > 5.0) then
return f1(x)
else
return f2(x)
end
end
Double argument function
function main(x,y)
return max(x,y)
end
A real life example (add angle in degrees minutes seconds)
-- convert Degrees Minutes Seconds (DD.MMSS) to decimal
function toDecimal(x)
local d, tmp = modf(x)
local m, s = modf(tmp*100)
local r = d + (m * 1/60) + (s * 100/3600)
return r
end
-- convert decimal degrees to DMS
function toDMS(x)
local d = floor(x)
local mt = (x - d) * 60
local m = floor(mt)
local st = mt - m
local s = st * 60
return d + m/100 + s/10000
end
-- Add DMS (input format DD.MMSS)
function lua_main(x,y)
return toDMS( toDecimal(x) + toDecimal(y) )
end
customfuncs.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>FormatVersion</key>
<integer>1</integer>
<!--
keyPRC
P - page
R - row
C - column
-->
<key>keyPRC</key>
<array>
<string>key_label</string>
<string>function_filename</string>
<string>entry_point</string>
<integer>parameters_in</integer>
<integer>parameters_out</integer>
</array>
<key>key001</key>
<array>
<string>max</string>
<string>func001.lua</string>
<string>main</string>
<integer>2</integer>
<integer>1</integer>
</array>
</dict>
</plist>
MAcalc Pro Lua extensions
- macalc.sto(index,X)
store X in a MAcalc storage register at position 'index' - macalc.rcl(index)
retrieve a value from a MAcalc storage register at position 'index'
Lua fuctions available in MAcalc Pro
- string. YES
- table. YES
- math. YES (don't use math. prefix, MAcalc will insert it for you)
- package. NO
- io. NO
- os. NO
- debug. NO
- file: NO
For information on Lua please see:
www.lua.org
Lua Reference Manual: Lua 5.1