Skip to content

Scripting

jbosh edited this page Nov 6, 2014 · 4 revisions

Holy cow when did they add scripting? 3.1.3.

Scripts Directory

Scripts are located in the following locations:
Windows: C:\<username>\AppData\Roaming\Calculator\scripts\*
Linux: Don't know right now
OS X: Don't know, somewhere

Files

Every file in this directory is read at load time. The name of the file will become the name of the scripts. For example a file named add5.txt in the scripts directory will turn into the function "add5" in the calculator. The input to the function is a variable named "value".

Examples

add5.txt - adds 5 to the input.
Usage: add5(2) becomes 7.

value + 5

_mm_cmpgt_ps.txt - yeah, we're going simd on this next one. MS Link. This one has examples of using variables.
Usage: _mm_cmpgt_ps{{0;1;2;3};{3;2;1;0}} becomes {0;0;0xFFFFFFFF;0xFFFFFFFF}.

v0 = vget_lane{value; 0}
v1 = vget_lane{value; 1}
x0 = vget_lane{v0; 0}
y0 = vget_lane{v0; 1}
z0 = vget_lane{v0; 2}
w0 = vget_lane{v0; 3}
x1 = vget_lane{v1; 0}
y1 = vget_lane{v1; 1}
z1 = vget_lane{v1; 2}
w1 = vget_lane{v1; 3}
result = {0;0;0;0}
result = vset_lane{result; 0; x0 > x1 ? 0xffffffff : 0}
result = vset_lane{result; 1; y0 > y1 ? 0xffffffff : 0}
result = vset_lane{result; 2; z0 > z1 ? 0xffffffff : 0}
result = vset_lane{result; 3; w0 > w1 ? 0xffffffff : 0}

Quick Scripts

You can now just write scripts in line.
func=>value + 5 creates a function called func that adds 5 to the value passed in.
func(4) becomes 9.

Clone this wiki locally