Comments start with '#' and extend to the end of the line.
To include some other source file, use the special include
comment (note the double-#
, and no quotes around the file name):
## include foo.gs
Numbers are 64 bit signed integers. Numerical and string constants are given in a C-like way.
123
-456
0x4567
"Hi there\n"
'\033'
'\x1b'
'\u20ac'
Strings are not zero-terminated and can contain any data (including zeros). Use \xNN
to set arbitray binary values.
Use \uNNNN
or \UNNNNNNNN
to include UTF8-encoded Unicode characters.
"1 Euro = 1 €\n"
"1 Euro = 1 \u20ac\n"
"1 Euro = 1 \xe2\x82\xac\n"
Logical operations return values of type bool. They are not identical with integers.
true
false
There is a special value nil. It is not the same as 0.
nil
-
-
( — code1 )
Put a reference to the following code block on the stack. The code block starts after the opening
{
and extends to (and including) the matching closing}
.This special word is handled while converting the source code into binary code with
gfxboot-compile
. For this reason, this is the only word that cannot be redefined.Examples{ "Hello!" show }
-
-
-
( — )
This marks the end of a code block. When the code is executed, the interpreter leaves the current execution context and returns to the parent context.
Examples/hello { "Hello!" show } def hello # print "Hello!"
-
-
-
( — mark1 )
mark1: hash start marker
Put hash start marker on stack. Hash definition is completed with ).
Examples( "foo" 10 "bar" 20 ) # hash with 2 keys "foo" and "bar"
-
-
-
( mark1 any1 … anyn — hash1 )
mark1: array start marker
any1 … anyn: some key - value pairs
hash1: new hash
Search for mark1 on the stack and put everything between mark1 and TOS into a hash. The elements are interpreted alternatingly as key and value. If there’s an odd number of elements on the stack, the last value is nil.
Examples( "foo" 10 "bar" 20 ) # hash with 2 keys "foo" and "bar"
-
-
-
( — mark1 )
mark1: array start marker
Put array start marker on stack. Array definition is completed with ].
Examples[ 1 2 3 ] # array with 3 elements
-
-
-
( mark1 any1 … anyn — array1 )
mark1: array start marker
any1 … anyn: some elements
array1: new array
Search for mark1 on the stack and put everything between mark1 and TOS into an array.
Examples[ 10 20 "some" "text" ] # array with 4 elements
-
-
-
( int1 — int2 )
int2: |int1|
-
( bool1 — bool2 )
bool2: bool1
Absolute value of int1 (change sign if int1 is negative).
ExamplesFor boolean 1 bit arithmetic the value is unchanged. -20 abs # 20 true abs # true
-
-
-
( int1 int2 — int3 )
int3: int1 + int2
-
( bool1 bool2 — bool3 )
bool3: bool1 xor bool2
-
( array1 array2 — array3 )
array3: array2 appended to array1
-
( hash1 hash2 — hash3 )
hash3: joined hash1 and hash2
-
( string1 string2 — string3 )
string3: string2 appended to string1
Add two numbers, or concatenate two arrays, or join two hashes, or concatenate two strings.
For boolean 1 bit arithmetic this is equivalent to 'xor'.
Examples10 20 add # 30 true true add # false [ 10 20 ] [ 30 40 ] add # [ 10 20 30 40 ] ( "foo" 10 ) ( "bar" 20 ) add # ( "bar" 20 "foo" 10 ) "abc" "def" add # "abcdef"
-
-
-
( int1 int2 — int3 )
int3: int1 and int2
-
( bool1 bool2 — bool3 )
bool3: bool1 and bool2
Examples15 4 and # 4 true false and # false
-
-
-
( canvas1 canvas2 — )
Copy from the drawing region of canvas2 to the drawing region of canvas1, at the drawing pos of canvas1 using the drawing mode of canvas1.
Examples# show cat picture /cat_pic "cat.jpg" readfile unpackimage def 300 200 setpos getcanvas cat_pic blt
See also: dim, drawline, fillrect, getbgcolor, getcanvas, getcolor, getcompose, getconsole, getdrawmode, getfont, getlocation, getpixel, getpos, getregion, newcanvas, newfont, putpixel, setbgcolor, setcanvas, setcolor, setcompose, setconsole, setdrawmode, setfont, setlocation, setpos, setregion, show, unpackimage, updatescreen
-
-
-
( int1 int2 — int3 )
int3: int1 <⇒ int2
-
( bool1 bool2 — int4 )
int4: bool1 <⇒ bool2
-
( string1 string2 — int5 )
int5: string1 <⇒ string2
-
( any1 any2 — int6 )
int6: any1 <⇒ any2
For pairs of booleans, integers, and strings the values are compared. For all other combinations the internal object id is compared.
The result is -1, 1, 0 if the first argument is less than, greater than, or equal to the second argument, respectively.
Examples10 20 cmp # -1 true false cmp # 1 "abc" "abc" cmp # 0 [ 10 20 ] [ 10 20 ] cmp # varies 0 false cmp # varies 0 nil cmp # varies "abc" [ 10 ] cmp # varies /foo [ 10 20 ] def /bar foo def foo bar cmp # 0
-
-
-
( — )
Stop code execution and start debug console.
You can leave (and re-enter) the debug console with
^D
but note that this doesn’t resume program execution. Use therun
(orr
) console command for this.Examples/foo { debug 10 20 } def foo # activate debug console when 'foo' is run
-
-
decodeutf8 - decode Unicode string
-
( string1 — array1 )
string1: UTF8-encoded string
array1: array with decoded chars
The array contains one element for each UTF8-encoded char. If string1 contains non-UTF8-chars they are represented as the negated 8-bit value.
Examples"ABC" decodeutf8 # [ 65 66 67 ] "Ä €" decodeutf8 # [ 196 32 8364 ] "A\xf0B" decodeutf8 # [ 65 -240 66 ]
See also: encodeutf8, format, freeze, readfile, string
-
-
-
( word1 any1 — )
If word1 does not exist, define word1 in the current context.
If word1 does already exist, redefine word1 in the context in which it is defined.
Examples/x 100 def # define x as 100 /neg { -1 mul } def # define a function that negates its argument
-
-
delete - delete an array, hash, or string element
-
( array1 int1 — )
array1: array to modify
int1: element index
-
( hash1 string1 — )
hash1: hash to modify
string1: key
-
( string2 int2 — )
string2: string to modify
int2: element index
Delete the respective element of array1, hash1, or string2. The length of array1 andstring_2 will be reduced by 1.
Note that string constants are read-only and cannot be modified.
Examples/x [ 10 20 30 ] def x 1 delete # x is now [ 10 30 ] /y ( "foo" 10 "bar" 20 ) def y "foo" delete # y is now ( "bar" 20 ) /z "ABC" mem def # mem is needed to create a writable copy z 1 delete # z is now "AC"
-
-
dim - get graphics object dimension
-
( canvas1 — int1 int2 )
-
( font1 — int1 int2 )
-
( canvas1 — int1 int2 )
int1: width
int2: height
Get dimension of graphics object. For a canvas it is its size, for a fixed size font it is its glyph size, for proportional font the width is 0 and the height is the font height.
Examplesgetconsole dim # 640 480 getconsole getfont dim # 8 16
See also: blt, drawline, fillrect, getbgcolor, getcanvas, getcolor, getcompose, getconsole, getdrawmode, getfont, getlocation, getpixel, getpos, getregion, newcanvas, newfont, putpixel, setbgcolor, setcanvas, setcolor, setcompose, setconsole, setdrawmode, setfont, setlocation, setpos, setregion, show, unpackimage, updatescreen
-
-
-
( int1 int2 — int3 )
int3: int1 / int2
-
( bool1 bool2 — bool3 )
bool3: bool1 / bool2
Divide int1 by int2.
You can do a 1 bit division with boolean values. Note that this will run into a division by zero exception if bool2 is false.
Examples200 30 div # 6 true true div # true
-
-
-
( int1 int2 — )
int1: x
int2: y
Draw line from current position to the specified x and y coordinates using the current color. The drawing position is updated to the end position. Line segments outside the drawing region are not drawn.
Examples100 200 drawline
See also: blt, dim, fillrect, getbgcolor, getcanvas, getcolor, getcompose, getconsole, getdrawmode, getfont, getlocation, getpixel, getpos, getregion, newcanvas, newfont, putpixel, setbgcolor, setcanvas, setcolor, setcompose, setconsole, setdrawmode, setfont, setlocation, setpos, setregion, show, unpackimage, updatescreen
-
-
-
( any1 — any1 any1 )
Duplicate the top-of-stack element.
Examples10 dup # 10 10
-
-
encodeutf8 - encode Unicode string
-
( array1 — string1 )
array1: array with decoded chars
string1: UTF8-encoded string
The array contains one element for each UTF8-encoded char. If string1 should contain non-UTF8-chars they are represented as the negated 8-bit value in array1.
Examples[ 65 66 67 ] encodeutf8 # "ABC" [ 196 32 8364 ] encodeutf8 # "Ä €" [ 65 -240 66 ] encodeutf8 # "A\xf0B"
See also: decodeutf8, format, freeze, readfile, string
-
-
-
( bool1 bool2 — bool3 )
bool3: bool1 == bool2
-
( int1 int2 — bool4 )
bool4: int1 == int2
-
( string1 string2 — bool5 )
bool5: string1 == string2
-
( any1 any2 — bool6 )
bool6: any1 == any2
For pairs of booleans, integers, and strings the values are compared. For all other combinations the internal object id is compared.
Examples10 20 eq # false true false eq # false "abc" "abc" eq # true [ 10 20 ] [ 10 20 ] eq # false 0 false eq # false 0 nil eq # false "abc" [ 10 ] eq # false /foo [ 10 20 ] def /bar foo def foo bar eq # true
-
-
exch - swap upper two stack elements
-
( any1 any2 — any2 any1 )
Swap the two topmost stack elements.
Examples10 20 exch # 20 10
-
-
-
( ref1 — )
ref1: word reference
-
( code1 — )
code1: code block
Executes the given code block or looks up and executes the word reference.
Examples{ 10 20 } exec # 10 20 /foo "abc" def foo # "abc" /foo exec # "abc"
-
-
exit - leave loop/repeat/for/forall loop
-
( — )
Exit from current loop.
Examples0 1 10 { dup 4 eq { exit } if } for # 0 1 2 3 4
-
-
fillrect - draw filled rectangle
-
( int1 int2 — )
int1: width
int2: height
Draw filled rectangle (using current color) at current position. The rectangle is clipped at the current drawing region.
Examples200 100 fillrect
See also: blt, dim, drawline, getbgcolor, getcanvas, getcolor, getcompose, getconsole, getdrawmode, getfont, getlocation, getpixel, getpos, getregion, newcanvas, newfont, putpixel, setbgcolor, setcanvas, setcolor, setcompose, setconsole, setdrawmode, setfont, setlocation, setpos, setregion, show, unpackimage, updatescreen
-
-
for - run code block repeatedly, with counter
-
( int1 int2 int3 code1 — )
int1: start value
int2: increment value
int3: maximum value (inclusive)
Run code1 repeatedly and put the current counter value on the stack in every iteration.
The counter starts with int1 and is incremented by int2 until it reaches int3. The code block is executed with the start value and then as long as the counter is less than or equal to the maximum value.
The increment may be negative. In that case the loop is executed as long as the counter is greater than or equal to the maximum value.
If the increment is 0, the loop is not executed.
Examples0 1 4 { } for # 0 1 2 3 4 0 -2 -5 { } for # 0 -2 -4
-
-
forall - loop over all elements
-
( array1 code1 — )
-
( hash1 code1 — )
-
( string1 code1 — )
Run code1 for each element of array1, hash1, or string1.
For array1 and string1, each element is put on the stack and code1 is run.
For hash1, each key and value pair are put on the stack and code1 is run. The hash keys are iterated in alphanumerical order.
Note that string1 is interpreted as a sequence of bytes, not UTF8-encoded characters.
Examples[ 10 20 30 ] { } forall # 10 20 30 ( "foo" 10 "bar" 20 ) { } forall # "bar" 20 "foo" 10 "ABC" { } forall # 65 66 67
-
-
-
( string1 array1 — string2 )
string1: printf-style format string
array1: array with to-be-formatted arguments
string2: formatted string
Examples"int = %d" [ 200 ] format # "int = 200" "string = %s" [ "foo" ] format # "string = foo" "%s: %d" [ "bar" 33 ] format # "bar: 33"
See also: decodeutf8, encodeutf8, freeze, readfile, string
-
-
freeze - make object read-only
-
( any1 — any1 )
Make any object read-only. A read-only object cannot be modified.
Note that string constants are read-only by default.
Examples[ 10 20 30 ] freeze # [ 10 20 30 ] 0 delete # raises 'readonly' exception
See also: decodeutf8, encodeutf8, format, readfile, string
-
-
-
( word1 any1 — )
Define word1 in the global context.
Examples/foo 300 gdef # define global word foo as 300
-
-
-
( bool1 bool2 — bool3 )
bool3: bool1 >= bool2
-
( int1 int2 — bool4 )
bool4: int1 >= int2
-
( string1 string2 — bool5 )
bool5: string1 >= string2
-
( any1 any2 — bool6 )
bool6: any1 >= any2
For pairs of booleans, integers, and strings the values are compared. For all other combinations the internal object id is compared.
Examples10 20 ge # false true false ge # true "abd" "abc" ge # true [ 10 20 ] [ 10 20 ] ge # varies 0 false ge # varies 0 nil ge # varies "abc" [ 10 ] ge # varies
-
-
get - get array, hash, or string element
-
( array1 int1 — )
array1: array to modify
int1: element index
-
( hash1 string1 — )
hash1: hash to modify
string1: key
-
( string2 int2 — )
string2: string to modify
int2: element index
Read the respective element of array1, hash1, or string2.
Examples[ 10 20 30 ] 2 get # 30 ( "foo" 10 "bar" 20 ) "foo" get # 10 "ABC" 1 get # 66
-
-
getbgcolor - get background color
-
( — int1 )
int1: color
Return current background color.
A color is a RGB value with red in bits 16-23, green in bits 8-15 and blue in bits 0-7. This is independent of what the graphics card is actually using.
Examplesgetcolor # 0 (black)
See also: blt, dim, drawline, fillrect, getcanvas, getcolor, getcompose, getconsole, getdrawmode, getfont, getlocation, getpixel, getpos, getregion, newcanvas, newfont, putpixel, setbgcolor, setcanvas, setcolor, setcompose, setconsole, setdrawmode, setfont, setlocation, setpos, setregion, show, unpackimage, updatescreen
-
-
getcanvas - get default canvas
-
( — canvas1 )
-
( — nil )
Get default canvas used for graphics operations. If none has been set, return nil.
A canvas has associated - a size and position on screen (see 'getlocation') - a rectangular region used for drawing and clipping (see 'getregion') - a cursor position (see 'getpos') - a font (see 'getfont') - a color (see 'getcolor') - a background color - used in debug console (see 'getbgcolor') - a drawing mode (see 'getdrawmode')
+ .Examples
# get current default canvas /current_canvas getcanvas def
+ See also: blt, dim, drawline, fillrect, getbgcolor, getcolor, getcompose, getconsole, getdrawmode, getfont, getlocation, getpixel, getpos, getregion, newcanvas, newfont, putpixel, setbgcolor, setcanvas, setcolor, setcompose, setconsole, setdrawmode, setfont, setlocation, setpos, setregion, show, unpackimage, updatescreen
-
-
-
( — int1 )
int1: color
Return current drawing color.
A color is a RGB value with red in bits 16-23, green in bits 8-15 and blue in bits 0-7. This is independent of what the graphics card is actually using.
Examplesgetcolor # 0xffffff (white)
See also: blt, dim, drawline, fillrect, getbgcolor, getcanvas, getcompose, getconsole, getdrawmode, getfont, getlocation, getpixel, getpos, getregion, newcanvas, newfont, putpixel, setbgcolor, setcanvas, setcolor, setcompose, setconsole, setdrawmode, setfont, setlocation, setpos, setregion, show, unpackimage, updatescreen
-
-
-
( — array1 )
-
( — nil )
Get current compose list. If none has been set, return nil.
The compose list is an array of graphics states.
Examples/current_list getcompose def # get current list of visible graphics states
See also: blt, dim, drawline, fillrect, getbgcolor, getcanvas, getcolor, getconsole, getdrawmode, getfont, getlocation, getpixel, getpos, getregion, newcanvas, newfont, putpixel, setbgcolor, setcanvas, setcolor, setcompose, setconsole, setdrawmode, setfont, setlocation, setpos, setregion, show, unpackimage, updatescreen
-
-
getconsole - get debug console canvas
-
( — canvas1 )
-
( — nil )
Get canvas of the debug console. If none has been set, return nil.
Examples# get console font /console_font getconsole getfont def
See also: blt, dim, drawline, fillrect, getbgcolor, getcanvas, getcolor, getcompose, getdrawmode, getfont, getlocation, getpixel, getpos, getregion, newcanvas, newfont, putpixel, setbgcolor, setcanvas, setcolor, setcompose, setconsole, setdrawmode, setfont, setlocation, setpos, setregion, show, unpackimage, updatescreen
-
-
getdict - get active dictionary
-
( — hash1 )
-
( — nil )
hash1: dictionary
Return the currently active dictionary or nil, if the current context does not (yet) have a dictionary.
A dictionary will only be created on demand - that is, the first time a word is defined in the current context.
When a program is started the global context is created containing a dictionary with all primitive words.
Examples/foo { getdict } def foo # nil /bar { /x 10 ldef getdict } def bar # ( /x 10 )
-
-
getdrawmode - get drawing mode
-
( — int1 )
int1: drawing mode
Return drawing mode of current canvas.
Drawing mode is either 0 (merge mode) or 1 (direct mode).
Examplesgetdrawmode # 0 ('merge' mode)
See also: blt, dim, drawline, fillrect, getbgcolor, getcanvas, getcolor, getcompose, getconsole, getfont, getlocation, getpixel, getpos, getregion, newcanvas, newfont, putpixel, setbgcolor, setcanvas, setcolor, setcompose, setconsole, setdrawmode, setfont, setlocation, setpos, setregion, show, unpackimage, updatescreen
-
-
-
( canvas1 — font1 )
-
( canvas1 — nil )
canvas1: canvas
font1: font
Get font used in canvas.
Examples# get currently used font getcanvas getfont
See also: blt, dim, drawline, fillrect, getbgcolor, getcanvas, getcolor, getcompose, getconsole, getdrawmode, getlocation, getpixel, getpos, getregion, newcanvas, newfont, putpixel, setbgcolor, setcanvas, setcolor, setcompose, setconsole, setdrawmode, setfont, setlocation, setpos, setregion, show, unpackimage, updatescreen
-
-
-
( canvas1 — int1 int2 )
canvas1: canvas
int1: x
int2: y
Get location associated with graphics state.
Examplesgetcanvas getlocation # 0 0
See also: blt, dim, drawline, fillrect, getbgcolor, getcanvas, getcolor, getcompose, getconsole, getdrawmode, getfont, getpixel, getpos, getregion, newcanvas, newfont, putpixel, setbgcolor, setcanvas, setcolor, setcompose, setconsole, setdrawmode, setfont, setlocation, setpos, setregion, show, unpackimage, updatescreen
-
-
getparent - get parent of context, font, or hash
-
( context1 — context2 )
context2: parent of context1 or nil
-
( font1 — font2 )
font2: parent of font1 or nil
-
( hash1 — hash2 )
hash2: parent of hash1 or nil
If a word lookup fails in a context, the lookup continues in the parent context.
If a glyph lookup fails in a font, the lookup continues in the parent font.
If a key cannot be found in a hash, the lookup continues in the parent hash.
Examples/x ( "foo" 10 "bar" 20 ) def /y ( "zap" 30 ) def x getparent # nil x y setparent x getparent # ( "zap" 30 )
-
-
-
( — int1 )
-
( — nil )
int1: color
Read pixel at drawing position from canvas in current graphics state. If the position is outside the drawing region, return nil.
Examplesgetpixel
See also: blt, dim, drawline, fillrect, getbgcolor, getcanvas, getcolor, getcompose, getconsole, getdrawmode, getfont, getlocation, getpos, getregion, newcanvas, newfont, putpixel, setbgcolor, setcanvas, setcolor, setcompose, setconsole, setdrawmode, setfont, setlocation, setpos, setregion, show, unpackimage, updatescreen
-
-
-
( — int1 int2 )
int1: x
int2: y
Return current drawing position. The position is relative to the drawing region in the graphics state.
Examplesgetpos # 0 0
See also: blt, dim, drawline, fillrect, getbgcolor, getcanvas, getcolor, getcompose, getconsole, getdrawmode, getfont, getlocation, getpixel, getregion, newcanvas, newfont, putpixel, setbgcolor, setcanvas, setcolor, setcompose, setconsole, setdrawmode, setfont, setlocation, setpos, setregion, show, unpackimage, updatescreen
-
-
getregion - get drawing region
-
( canvas1 — int1 int2 int3 int4 )
canvas1: canvas
int1: x
int2: y
int3: width
int4: height
Get drawing region associated with graphics state. Any drawing operation will be relative to this region. Graphics output will be clipped at the region boundaries.
Examplesgetcanvas getregion # 0 0 800 600
See also: blt, dim, drawline, fillrect, getbgcolor, getcanvas, getcolor, getcompose, getconsole, getdrawmode, getfont, getlocation, getpixel, getpos, newcanvas, newfont, putpixel, setbgcolor, setcanvas, setcolor, setcompose, setconsole, setdrawmode, setfont, setlocation, setpos, setregion, show, unpackimage, updatescreen
-
-
-
( bool1 bool2 — bool3 )
bool3: bool1 > bool2
-
( int1 int2 — bool4 )
bool4: int1 > int2
-
( string1 string2 — bool5 )
bool5: string1 > string2
-
( any1 any2 — bool6 )
bool6: any1 > any2
For pairs of booleans, integers, and strings the values are compared. For all other combinations the internal object id is compared.
Examples10 20 gt # false true false gt # true "abd" "abc" gt # true [ 10 20 ] [ 10 20 ] gt # varies 0 false gt # varies 0 nil gt # varies "abc" [ 10 ] gt # varies
-
-
-
(bool1 code1 — )
-
(int1 code1 — )
-
(nil code1 — )
-
(any1 code1 — )
code1: code block to run if condition evaluates to 'true'
The condition is false for: boolean false, integer 0, or nil. In all other cases it is true.
Examplestrue { "ok" show } if # "ok" 50 { "ok" show } if # "ok" nil { "ok" show } if # shows nothing "" { "ok" show } if # "ok"
-
-
ifelse - conditional execution
-
(bool1 code1 code2 — )
-
(int1 code1 code2 — )
-
(nil code1 code2 — )
-
(any1 code1 code2 — )
code1: code block to run if condition evaluates to 'true'
code2: code block to run if condition evaluates to 'false'
The condition is false for: boolean false, integer 0, or nil. In all other cases it is true.
Examplesfalse { "ok" } { "bad" } ifelse show # "bad" 20 { "ok" } { "bad" } ifelse show # "ok" nil { "ok" } { "bad" } ifelse sho # "bad" "" { "ok" } { "bad" } ifelse show # "ok"
-
-
-
( anyn … any0 int1 — anyn … any0 anyn )
int1: element position on stack (n is equal to int1)
Copy the int1-th-from-top element on the top-of-stack.
Examples10 20 30 40 3 index # 10 20 30 40 10 /dup { 0 index } def # definition of 'dup' /over { 1 index } def # definition of 'over'
-
-
-
( word1 any1 — )
Define word1 in the current local context.
Examples/foo 200 ldef # define local word foo as 200
-
-
-
( bool1 bool2 — bool3 )
bool3: bool1 ⇐ bool2
-
( int1 int2 — bool4 )
bool4: int1 ⇐ int2
-
( string1 string2 — bool5 )
bool5: string1 ⇐ string2
-
( any1 any2 — bool6 )
bool6: any1 ⇐ any2
For pairs of booleans, integers, and strings the values are compared. For all other combinations the internal object id is compared.
Examples10 20 le # true true false le # false "abd" "abc" le # false [ 10 20 ] [ 10 20 ] le # varies 0 false le # varies 0 nil le # varies "abc" [ 10 ] le # varies
-
-
length - get size of array, hash, or string
-
( array1 — int1 )
int1: number of elements in array1
-
( hash1 — int2 )
int2: number of key - value pairs in hash1
-
( string1 — int3 )
int3: number of bytes in string1
Put the length of array1, hash1, or string1 on the stack.
Examples[ 10 20 30 ] length # 3 ( "foo" 10 "bar" 20 ) length # 2 "ABC" length # 3
-
-
-
( code1 — )
Repeat code1 forever until you exit the loop explicitly.
Examples{ "Help!" show } loop
-
-
-
( bool1 bool2 — bool3 )
bool3: bool1 < bool2
-
( int1 int2 — bool4 )
bool4: int1 < int2
-
( string1 string2 — bool5 )
bool5: string1 < string2
-
( any1 any2 — bool6 )
bool6: any1 < any2
For pairs of booleans, integers, and strings the values are compared. For all other combinations the internal object id is compared.
Examples10 20 lt # true true false lt # false "abd" "abc" lt # false [ 10 20 ] [ 10 20 ] lt # varies 0 false lt # varies 0 nil lt # varies "abc" [ 10 ] lt # varies
-
-
-
( int1 int2 — int3 )
int3: maximum(int1, int2)
-
( bool1 bool2 — bool3 )
bool3: bool1 or bool2
int3 is the larger value of int1 and int2.
For boolean 1 bit arithmetic this is equivalent to 'or'
Examples10 20 max # 20 true false max # true
-
-
-
( int1 int2 — int3 )
int3: minimum(int1, int2)
-
( bool1 bool2 — bool3 )
bool3: bool1 and bool2
int3 is the smaller value of int1 and int2.
For boolean 1 bit arithmetic this is equivalent to 'and'
Examples10 20 min # 10 true false min # false
-
-
-
( int1 int2 — int3 )
int3: int1 % int2
-
( bool1 bool2 — bool3 )
bool3: bool1 / bool2
int3 is the remainder dividing int1 by int2.
You can get the remainder from a 1 bit division with boolean values. Note that this will run into a division by zero exception if bool2 is false.
Examples200 30 mod # 20 true true mod # false
-
-
-
( int1 int2 — int3 )
int3: int1 * int2
-
( bool1 bool2 — bool3 )
bool3: bool1 and bool2
Multiply int1 by int2.
For boolean 1 bit arithmetic this is equivalent to 'and'.
Examples20 30 mul # 600 true false mul # false
-
-
-
( bool1 bool2 — bool3 )
bool3: bool1 != bool2
-
( int1 int2 — bool4 )
bool4: int1 != int2
-
( string1 string2 — bool5 )
bool5: string1 != string2
-
( any1 any2 — bool6 )
bool6: any1 != any2
For pairs of booleans, integers, and strings the values are compared. For all other combinations the internal object id is compared.
Examples10 20 ne # true true false ne # true "abc" "abc" ne # false [ 10 20 ] [ 10 20 ] ne # true 0 false ne # true 0 nil ne # true "abc" [ 10 ] ne # true /foo [ 10 20 ] def /bar foo def foo bar ne # false
-
-
-
( int1 — int2 )
int2: -int1
-
( bool1 — bool2 )
bool2: -bool1
Negate int1 (change sign).
For boolean 1 bit arithmetic the value is unchanged (this is not a 'not' operation).
Examples20 neg # -20 true neg # true
-
-
-
( int1 int2 — canvas1 )
int1: width
int2: height
Create a new empty canvas of the specified size.
Examples800 600 newcanvas
See also: blt, dim, drawline, fillrect, getbgcolor, getcanvas, getcolor, getcompose, getconsole, getdrawmode, getfont, getlocation, getpixel, getpos, getregion, newfont, putpixel, setbgcolor, setcanvas, setcolor, setcompose, setconsole, setdrawmode, setfont, setlocation, setpos, setregion, show, unpackimage, updatescreen
-
-
-
( string1 — font1 )
-
( string1 — nil )
string1: font data
font1: font object
Parse font data in string1 and create font object. If string1 does not contain valid font data, return nil.
Examples/foo_font "foo.fnt" readfile newfont def # create font from file "foo.fnt"
See also: blt, dim, drawline, fillrect, getbgcolor, getcanvas, getcolor, getcompose, getconsole, getdrawmode, getfont, getlocation, getpixel, getpos, getregion, newcanvas, putpixel, setbgcolor, setcanvas, setcolor, setcompose, setconsole, setdrawmode, setfont, setlocation, setpos, setregion, show, unpackimage, updatescreen
-
-
-
( int1 — int2 )
int2: -int1 - 1
-
( bool1 — bool2 )
bool2: !bool1
Examples20 not # -21 true not # false
-
-
-
( int1 int2 — int3 )
int3: int1 or int2
-
( bool1 bool2 — bool3 )
bool3: bool1 or bool2
Examples15 4 or # 15 true false or # true
-
-
-
( any1 any2 — any1 any2 any1 )
Put a copy of the second-from-top element on the top-of-stack.
Examples10 20 over # 10 20 10
-
-
-
( any1 — )
Remove the top-of-stack element.
Examples10 20 pop # 10
-
-
put - set array, hash, or string element
-
( array1 int1 any1 — )
array1: array to modify
int1: element index
any1: new value
-
( hash1 string1 any2 — )
hash1: hash to modify
string1: key
any2: new value
-
( string2 int2 int3 — )
string2: string to modify
int2: element index
int3: new value
Set the respective element of array1, hash1, or string2.
Note that string constants are read-only and cannot be modified.
Examples/x [ 10 20 30 ] def x 2 40 put # x is now [ 10 20 40 ] /y ( "foo" 10 "bar" 20 ) def y "bar" 40 put # y is now ( "foo" 10 "bar" 40 ) /z "ABC" mem def # mem is needed to create a writable copy z 1 68 put # z is now "ADC"
-
-
-
( — )
Set pixel with current color at drawing position in canvas in current graphics state. If the position is outside the drawing region, nothing is drawn.
Examplessetpixel
See also: blt, dim, drawline, fillrect, getbgcolor, getcanvas, getcolor, getcompose, getconsole, getdrawmode, getfont, getlocation, getpixel, getpos, getregion, newcanvas, newfont, setbgcolor, setcanvas, setcolor, setcompose, setconsole, setdrawmode, setfont, setlocation, setpos, setregion, show, unpackimage, updatescreen
-
-
-
( string1 — string2 )
-
( string1 — nil )
string1: file name
string2: file content
Read entire file and return its content. If the file could not be read, return nil.
Examples"foo" readfile
See also: decodeutf8, encodeutf8, format, freeze, string
-
-
-
( int1 code1 — )
Repeat code1 int1 times. If int1 is less or equal to 0, code1 is not run.
Examples3 { "Help!" show } repeat # "Help!Help!Help!"
-
-
return - leave current function
Exit from currently running function.
Examples/foo { dup nil eq { return } if show } def "abc" foo # shows "abc" nil foo # does nothing
-
-
( any1 … anyn int1 int2 — anyx … anyy )
int1: number of stack elements to rotate (equal to index n)
int2: rotation amount
Rotate the n elements any1 … anyn. The new positions are calculated as follows:
x = (1 - int2) mod int1
y = (n - int2) mod int1
This can be seen as rotating int1 elements up by int2 resp. down by -int2.
Examples10 20 30 40 50 5 2 roll # 40 50 10 20 30 /rot { 3 -1 roll } def # definition of 'rot'
-
-
rot - rotate upper three stack elements
-
( any1 any2 any3 — any2 any3 any1 )
Rotate any1 to the top-of-stack.
Examples10 20 30 rot # 20 30 10
-
-
-
( string1 — )
string1: binary code
Load binary code and run it.
Note: unlike 'exec' this does not open a new context but replaces the currently running code with the new one.
Examples"new_program" readfile run
-
-
setbgcolor - set background color
-
( int1 — )
int1: color
Set current background color.
A color is a RGB value with red in bits 16-23, green in bits 8-15 and blue in bits 0-7. This is independent of what the graphics card is actually using.
Examples0xff00 setcolor # green
See also: blt, dim, drawline, fillrect, getbgcolor, getcanvas, getcolor, getcompose, getconsole, getdrawmode, getfont, getlocation, getpixel, getpos, getregion, newcanvas, newfont, putpixel, setcanvas, setcolor, setcompose, setconsole, setdrawmode, setfont, setlocation, setpos, setregion, show, unpackimage, updatescreen
-
-
setcanvas - set default canvas
-
( canvas1 — )
-
( nil — )
Set default canvas. If nil is passed, there will be no default canvas.
Examples/saved_state getcanvas def # save current graphics state ... saved_state setcanvas # restore saved graphics state
See also: blt, dim, drawline, fillrect, getbgcolor, getcanvas, getcolor, getcompose, getconsole, getdrawmode, getfont, getlocation, getpixel, getpos, getregion, newcanvas, newfont, putpixel, setbgcolor, setcolor, setcompose, setconsole, setdrawmode, setfont, setlocation, setpos, setregion, show, unpackimage, updatescreen
-
-
-
( int1 — )
int1: color
Set current drawing color.
A color is a RGB value with red in bits 16-23, green in bits 8-15 and blue in bits 0-7. This is independent of what the graphics card is actually using.
Examples0xff0000 setcolor # red
See also: blt, dim, drawline, fillrect, getbgcolor, getcanvas, getcolor, getcompose, getconsole, getdrawmode, getfont, getlocation, getpixel, getpos, getregion, newcanvas, newfont, putpixel, setbgcolor, setcanvas, setcompose, setconsole, setdrawmode, setfont, setlocation, setpos, setregion, show, unpackimage, updatescreen
-
-
-
( array1 — )
-
( nil — )
Set current compose list. If nil is passed, the current list is removed.
The compose list is an array of canvas objects.
Examples/saved_list getcompose def # save current list ... saved_list setcompose # restore list
See also: blt, dim, drawline, fillrect, getbgcolor, getcanvas, getcolor, getcompose, getconsole, getdrawmode, getfont, getlocation, getpixel, getpos, getregion, newcanvas, newfont, putpixel, setbgcolor, setcanvas, setcolor, setconsole, setdrawmode, setfont, setlocation, setpos, setregion, show, unpackimage, updatescreen
-
-
setconsole - set debug console canvas
-
( canvas1 — )
-
( nil — )
Set canvas of the debug console. If nil is passed, the current canvas is removed (and debug console disabled).
You can use this to change the appearance of the debug console.
Examples# change debug console backgound color to transparent light blue getcanvas getconsole setcanvas 0x40405070 setbgcolor setcanvas
See also: blt, dim, drawline, fillrect, getbgcolor, getcanvas, getcolor, getcompose, getconsole, getdrawmode, getfont, getlocation, getpixel, getpos, getregion, newcanvas, newfont, putpixel, setbgcolor, setcanvas, setcolor, setcompose, setdrawmode, setfont, setlocation, setpos, setregion, show, unpackimage, updatescreen
-
-
setdict - set active dictionary
-
( hash1 — )
-
( nil — )
hash1: new active dictionary
Set the currently active dictionary. With nil, the dictionary is removed from the current context.
Examples/foo { /x 10 ldef x } def foo # 10 /bar { ( /x 10 ) setdict x } def bar # 10
-
-
setdrawmode - set drawing mode
-
( int1 — )
int1: drawing mode
Set drawing mode if current canvas.
Drawing mode is either 0 (merge mode) or 1 (direct mode).
Examples1 setdrawmode # set 'direct' mode
See also: blt, dim, drawline, fillrect, getbgcolor, getcanvas, getcolor, getcompose, getconsole, getdrawmode, getfont, getlocation, getpixel, getpos, getregion, newcanvas, newfont, putpixel, setbgcolor, setcanvas, setcolor, setcompose, setconsole, setfont, setlocation, setpos, setregion, show, unpackimage, updatescreen
-
-
-
( canvas1 font1 — )
-
( canvas1 nil — )
canvas1: canvas
font1: font
Set font used in canvas. If nil is passed, no font will be associated with canvas.
Examples# read font from file and use it /foo_font "foo.fnt" readfile newfont def getcanvas foo_font setfont
See also: blt, dim, drawline, fillrect, getbgcolor, getcanvas, getcolor, getcompose, getconsole, getdrawmode, getfont, getlocation, getpixel, getpos, getregion, newcanvas, newfont, putpixel, setbgcolor, setcanvas, setcolor, setcompose, setconsole, setdrawmode, setlocation, setpos, setregion, show, unpackimage, updatescreen
-
-
-
( canvas1 int1 int2 — )
canvas1: canvas
int1: x
int2: y
Set location associated with graphics state.
Examplesgetcanvas 10 10 setlocation
See also: blt, dim, drawline, fillrect, getbgcolor, getcanvas, getcolor, getcompose, getconsole, getdrawmode, getfont, getlocation, getpixel, getpos, getregion, newcanvas, newfont, putpixel, setbgcolor, setcanvas, setcolor, setcompose, setconsole, setdrawmode, setfont, setpos, setregion, show, unpackimage, updatescreen
-
-
setparent - set parent of context, font, or hash
-
( context1 context2 — )
-
( context1 nil — )
context2: new parent of context1
-
( font1 font2 — )
-
( font1 nil — )
font2: new parent of font1
-
( hash1 hash2 — )
-
( hash1 nil — )
hash2: new parent of hash1
If nil is used as second argument, any existing parent link is removed.
If a word lookup fails in a context, the lookup continues in the parent context.
If a glyph lookup fails in a font, the lookup continues in the parent font.
If a key cannot be found in a hash, the lookup continues in the parent hash.
Examples/x ( "foo" 10 "bar" 20 ) def /y ( "zap" 30 ) def x "zap" get # nil x y setparent x "zap" get # 30 x nil setparent x "zap" get # nil
-
-
-
( int1 int2 — )
int1: x
int2: y
Set drawing position. The position is relative to the drawing region in the graphics state.
Examples20 30 setpos
See also: blt, dim, drawline, fillrect, getbgcolor, getcanvas, getcolor, getcompose, getconsole, getdrawmode, getfont, getlocation, getpixel, getpos, getregion, newcanvas, newfont, putpixel, setbgcolor, setcanvas, setcolor, setcompose, setconsole, setdrawmode, setfont, setlocation, setregion, show, unpackimage, updatescreen
-
-
setregion - set drawing region
-
( canvas1 int1 int2 int3 int4 — )
canvas1: canvas
int1: x
int2: y
int3: width
int4: height
Set drawing region associated with graphics state. Any drawing operation will be relative to this region. Graphics output will be clipped at the region boundaries.
Examplesgetcanvas 10 10 200 100 setregion
See also: blt, dim, drawline, fillrect, getbgcolor, getcanvas, getcolor, getcompose, getconsole, getdrawmode, getfont, getlocation, getpixel, getpos, getregion, newcanvas, newfont, putpixel, setbgcolor, setcanvas, setcolor, setcompose, setconsole, setdrawmode, setfont, setlocation, setpos, show, unpackimage, updatescreen
-
-
-
( int1 int2 — int3 )
int3: int1 << int2
-
( bool1 bool2 — bool3 )
bool3: bool1 and !bool2
Examples1 4 shl # 16 true false shl # true
-
-
-
( string1 — )
Print string1 at current cursor position in canvas associated with current graphics state.
The cursor position is advanced to point at the end of the printed text. Newline ('\x0a') and carriage return ('\x0d') characters are interpreted and the cursor position is adjusted relative to the starting position.
Examples"Hello!" show # print "Hello!"
See also: blt, dim, drawline, fillrect, getbgcolor, getcanvas, getcolor, getcompose, getconsole, getdrawmode, getfont, getlocation, getpixel, getpos, getregion, newcanvas, newfont, putpixel, setbgcolor, setcanvas, setcolor, setcompose, setconsole, setdrawmode, setfont, setlocation, setpos, setregion, unpackimage, updatescreen
-
-
-
( int1 int2 — int3 )
int3: int1 >> int2
-
( bool1 bool2 — bool3 )
bool3: bool1 and !bool2
Examples16 4 shr # 1 true false shr # true
-
-
string - create or duplicate string
-
( int1 — string1 )
int1: length
string1: new string with length int1
-
( string2 — string3 )
string2: string to duplicate
string3: copy of string2
There are two variants: given a number, a string of that length is created and initialized with zeros; given a string, a copy of that string is created.
int1 may be 0 to create a zero-length string.
Note: duplication works for all string-like objects. For example for word references and even code blocks.
Examples2 string # creates an empty string of length 2: "\x00\x00" "abc" string # creates a copy of "abc" # even this works: /abc string # a copy of /abc { 10 20 } string # a copy of the code block { 10 20 }
See also: decodeutf8, encodeutf8, format, freeze, readfile
-
-
-
( int1 int2 — int3 )
int3: int1 - int2
-
( bool1 bool2 — bool3 )
bool3: bool1 xor bool2
Subtract int2 from int1.
For boolean 1 bit arithmetic this is equivalent to 'xor'.
Examples100 30 sub # 70 false true sub # true
-
-
-
( string1 — canvas1 )
-
( string1 — nil )
string1: image file data
Unpacks image and returns a canvas object with the image or nil if the data does not contain image data.
Examples"foo.jpg" readfile unpackimage
See also: blt, dim, drawline, fillrect, getbgcolor, getcanvas, getcolor, getcompose, getconsole, getdrawmode, getfont, getlocation, getpixel, getpos, getregion, newcanvas, newfont, putpixel, setbgcolor, setcanvas, setcolor, setcompose, setconsole, setdrawmode, setfont, setlocation, setpos, setregion, show, updatescreen
-
-
updatescreen - update screen region
-
( int1 int2 int3 int4 — )
int1: x
int2: y
int3: width
int4: height
Update (redraw) screen region.
Examples10 10 200 100 updatescreen
See also: blt, dim, drawline, fillrect, getbgcolor, getcanvas, getcolor, getcompose, getconsole, getdrawmode, getfont, getlocation, getpixel, getpos, getregion, newcanvas, newfont, putpixel, setbgcolor, setcanvas, setcolor, setcompose, setconsole, setdrawmode, setfont, setlocation, setpos, setregion, show, unpackimage
-
-
-
( int1 int2 — int3 )
int3: int1 xor int2
-
( bool1 bool2 — bool3 )
bool3: bool1 xor bool2
Examples15 4 xor # 11 true false or # true
-