BRL.Blitz: Globals Functions Keywords Source  


The Blitz runtime module provides low level functionality required by BlitzMax applications when they are running. This includes things like memory management, exception handling and string and array operations.

Much of the functionality provided by this module is hidden from application programmers, but is instead used 'behind the scenes' by the compiler. However, there are some very useful commands for debugging, memory management and simple standard IO.

Globals

AppDirApplication directory
AppFileApplication file name
AppTitleApplication title
AppArgsArguments passed to the application at startup
LaunchDirDirectory from which application was launched

Functions

RuntimeErrorGenerate a runtime error
DebugStopStop program execution and enter debugger
DebugLogWrite a string to debug log
OnEndAdd a function to be called when the program ends
ReadStdinRead a string from stdin
WriteStdoutWrite a string to stdout
WriteStderrWrite a string to stderr
DelayWait for a given number of milliseconds
MilliSecsGet millisecond counter
MemAllocAllocate memory
MemFreeFree allocated memory
MemExtendExtend a block of memory
MemClearClear a block of memory to 0
MemCopyCopy a non-overlapping block of memory
MemMoveCopy a potentially overlapping block of memory
GCSetModeSet garbage collector mode
GCSuspendSuspend garbage collector
GCResumeResume garbage collector
GCCollectRun garbage collector
GCMemAllocedMemory allocated by application
GCEnterPrivate: do not use
GCLeavePrivate: do not use
HandleFromObjectConvert object to integer handle
HandleToObjectConvert integer handle to object

Keywords

StrictSet strict mode
SuperStrictSet SuperStrict mode
EndEnd program execution
RemBegin a remark block
EndRemEnd a remark block
TrueConstant integer of value 1
FalseConstant integer of value 0
PiConstant Pi value: 3.1415926535897932384626433832795
NullGet Default Null value
ByteUnsigned 8 bit integer Type
ShortUnsigned 16 bit integer Type
IntSigned 32 bit integer Type
LongSigned 64 bit integer Type
Float32 bit Floating point Type
Double64 bit floating point Type
StringString Type
ObjectObject Type
VarComposite Type specifier for 'by reference' types
PtrComposite Type specifier for pointer types
IfBegin a conditional block.
ThenOptional separator between the condition and associated code in an If statement.
ElseElse provides the ability For an If Then construct to execute a second block of code when the If condition is False.
ElseIfElseIf provides the ability to test and execute a section of code if the initial condition failed.
EndIfMarks the End of an If Then block.
ForMarks the start of a loop that uses an iterator to execute a section of code repeatedly.
ToFollowed by a constant which is used to calculate when to exit a For..Next loop.
StepSpecifies an optional constant that is used to increment the For iterator.
NextEnd a For block
EachInIterate through an array or collection
WhileExecute a block of code While a condition is True
WendEnd a While block
EndWhileEnd a While block
RepeatExecute a block of code Until a termination condition is met, or Forever
UntilConditionally continue a Repeat block
ForeverContinue a Repeat block Forever
SelectBegin a Select block
EndSelectEnd a Select block
CaseConditional code inside a Select block
DefaultDefault code inside a Select block
ExitExit enclosing loop
ContinueContinue execution of enclosing loop
ConstDeclare a constant
LocalDeclare a Local variable
GlobalDeclare a Global variable
FieldDeclare a Field variable
FunctionBegin a Function declaration
EndFunctionEnd a Function declaration
ReturnReturn from a Function
TypeBegin a user defined Type declaration
EndTypeEnd a user defined Type declaration
ExtendsSpecify user defined Type supertype
MethodBegin a Method declaration
EndMethodEnd a Method declaration
AbstractDenote a Type or Method as Abstract
FinalDenote a Type or Method as Final
NewCreate an instance of a user defined Type
SelfReference to this Method's Object instance
SuperReference to the Super Type Object instance
DeleteReserved for future expansion
ReleaseRelease an integer Object handle
PublicPublic makes a Constant, Global variable or Function accessible from outside the current source file (Default)
PrivatePrivate makes a Constant, Global variable or Function only accessible from within the current source file
ExternExtern marks the beginning of an external list of Function declarations
EndExternEndExtern marks the End of an Extern section
ModuleDeclare Module scope and identifier
ModuleInfoDefine Module properties
IncbinEmbed a data file
IncbinPtrGet start address of embedded data file
IncbinLenGet length of embedded data file
IncludeInclude effectively 'inserts' the specified file into the file being compiled.
FrameworkFramework builds the BlitzMax application with only the Module specified rather than all modules installed.
ImportImport declarations from a Module or source file
AssertThrow a RuntimeError if a condition is False
GotoTransfer program flow to specified label
TryBegin declaration of a Try block
EndTryEnd declaration of a Try block
CatchCatch an exception Object in a Try block
ThrowThrow an exception Object to the enclosing Try block
DefDataDefine class BASIC style data
ReadDataRead classic BASIC style data
RestoreDataRestore classic BASIC style data
AndConditional 'And' binary operator
OrConditional 'Or' binary operator
NotConditional 'Not' binary operator
ShlBitwise 'Shift left' binary operator
ShrBitwise 'Shift right' binary operator
SarBitwise 'Shift arithmetic right' binary operator
LenNumber of characters in a String or elements in an array
AbsNumeric 'absolute value' unary operator
ModNumeric 'modulus' or 'remainder' binary operator
SgnNumeric 'sign' unary operator
MinNumeric 'minimum' builtin function
MaxNumeric 'maximum' builtin function
VarptrFind the address of a variable
SizeOfSize, in bytes, occupied by a variable, string, array or object
AscGet character value of the first character of a string
ChrCreate a string of length 1 with a character code

Global reference

Global AppDir$="bbAppDir"
DescriptionApplication directory
InformationThe AppDir global variable contains the fully qualified directory of the currently executing application. An application's initial current directory is also set to AppDir when an application starts.
Example
' appdir.bmx
' requests the user to select a file from the application's directory

Print "Application Directory="+AppDir$

file$=RequestFile("Select File to Open","",False,AppDir$)

Print "file selected was :"+file

Global AppFile$="bbAppFile"
DescriptionApplication file name
InformationThe AppFile global variable contains the fully qualified file name of the currently executing application.
Example
' appfile.bmx

Print "This program's executable is located at "+AppFile$

Global AppTitle$="bbAppTitle"
DescriptionApplication title
InformationThe AppTitle global variable is used by various commands when a default application title is required - for example, when opening simple windows or requesters.

Initially, AppTitle is set the value "BlitzMax Application". However, you may change AppTitle at any time with a simple assignment.

Global AppArgs$[]="bbAppArgs"
DescriptionArguments passed to the application at startup
InformationThe AppArgs global array contains the command line parameters sent to an application when it was started. The first element of AppArgs always contains the name of the application. However, the format of the name may change depending on how the application was launched. Use AppDir or AppFile for consistent information about the applications name or directory.
Example
' appargs.bmx
' print the command line arguments passed to the program at runtime

Print "Number of arguments = "+AppArgs.length

For a$=EachIn AppArgs
Print a$
Next

Global LaunchDir$="bbLaunchDir"
DescriptionDirectory from which application was launched
InformationThe LaunchDir global variable contains the current directory at the time the application was launched. This is mostly of use to command line tools which may need to access the 'shell' current directory as opposed to the application directory.
Example
' launchdir.bmx

Print "This program was launched from "+LaunchDir$

Function reference

Function RuntimeError( message$ )
DescriptionGenerate a runtime error
InformationThrows a TRuntimeException.
Example
' runtimeerror.bmx

If a=0 RuntimeError "This program has failed badly."

Function DebugStop()
DescriptionStop program execution and enter debugger
InformationIf there is no debugger present, this command is ignored.

Function DebugLog( message$ )
DescriptionWrite a string to debug log
InformationIf there is no debugger present, this command is ignored.

Function OnEnd( fun() )
DescriptionAdd a function to be called when the program ends
InformationOnEnd allows you to specify a function to be called when the program ends. OnEnd functions are called in the reverse order to that in which they were added.
Example
' onend.bmx

Function cleanup()
Print "cleaning up"
End Function

OnEnd cleanup
Print "program running"
End	'the cleanup function will be called at this time

Function ReadStdin$()
ReturnsA string read from stdin. The newline terminator, if any, is included in the returned string.
DescriptionRead a string from stdin

Function WriteStdout( str$ )
DescriptionWrite a string to stdout
InformationWrites str to stdout and flushes stdout.

Function WriteStderr( str$ )
DescriptionWrite a string to stderr
InformationWrites str to stderr and flushes stderr.

Function Delay( millis )
DescriptionWait for a given number of milliseconds
Information Delay suspends program execution for at least millis milliseconds.

A millisecond is one thousandth of a second.

Function MilliSecs()
ReturnsMilliseconds since computer turned on.
DescriptionGet millisecond counter
Information MilliSecs returns the number of milliseconds elapsed since the computer was turned on.

A millisecond is one thousandth of a second.

Function MemAlloc:Byte Ptr( size )
ReturnsA new block of memory size bytes long
DescriptionAllocate memory

Function MemFree( mem:Byte Ptr )
DescriptionFree allocated memory
InformationThe memory specified by mem must have been previously allocated by MemAlloc or MemExtend.

Function MemExtend:Byte Ptr( mem:Byte Ptr,size,new_size )
ReturnsA new block of memory new_size bytes long
DescriptionExtend a block of memory
InformationAn existing block of memory specified by mem and size is copied into a new block of memory new_size bytes long. The existing block is released and the new block is returned.

Function MemClear( mem:Byte Ptr,size )
DescriptionClear a block of memory to 0

Function MemCopy( dst:Byte Ptr,src:Byte Ptr,size )
DescriptionCopy a non-overlapping block of memory

Function MemMove( dst:Byte Ptr,src:Byte Ptr,size )
DescriptionCopy a potentially overlapping block of memory

Function GCSetMode( mode )
DescriptionSet garbage collector mode
Information mode can be one of the following:
1 : automatic GC - memory will be automatically garbage collected
2 : manual GC - no memory will be collected until a call to GCCollect is made

The default GC mode is automatic GC.

Function GCSuspend()
DescriptionSuspend garbage collector
Information GCSuspend temporarily suspends the garbage collector. No garbage collection will be performed following a call to GCSuspend.

Use GCResume to resume the garbage collector. Note that GCSuspend and GCResume 'nest', meaning that each call to GCSuspend must be matched by a call to GCResume.

Function GCResume()
DescriptionResume garbage collector
Information GCResume resumes garbage collection following a call to GCSuspend.

See GCSuspend for more details.

Function GCCollect()
ReturnsThe amount of memory, in bytes, collected.
DescriptionRun garbage collector
Information This function will have no effect if the garbage collector has been suspended due to GCSuspend.

Function GCMemAlloced()
ReturnsThe amount of memory, in bytes, currently allocated by the application
DescriptionMemory allocated by application
Information This function only returns 'managed memory'. This includes all objects, strings and arrays in use by the application.

Function GCEnter()
DescriptionPrivate: do not use

Function GCLeave()
DescriptionPrivate: do not use

Function HandleFromObject( obj:Object )
ReturnsAn integer object handle
DescriptionConvert object to integer handle
Information After converting an object to an integer handle, you must later release it using the Release command.

Function HandleToObject:Object( handle )
ReturnsThe object associated with the integer handle
DescriptionConvert integer handle to object

Keyword reference

Strict
DescriptionSet strict mode
Information See the BlitzMax Language Reference for more information on Strict mode programming.
Example
Rem
Strict advises the BlitzMax compiler to report as errors all auto defined variables.
End Rem

Strict

local a=10

b=20	'compiler error, strict mode means variables must be declared b4 use

SuperStrict
DescriptionSet SuperStrict mode

End
DescriptionEnd program execution
Example
Rem
The End command causes a program to exit immediately.
End Rem

Print "Hello!"
End
Print "This line will never be printed as the program has already been ended."

Rem
DescriptionBegin a remark block
Example
Rem

My Rem Example
First created 9th August, 2004

(C)2050 Blitz Intergalactic Software Corporation

End Rem

Print "This program has no useful function"

Rem

Remarks are useful for making your program easily readable.
You can leave details explaining the function of your program
in a remarks section so that you and any other programmers
that work with your code can more easily understand the workings
of your program

End Rem

Print "Sorry."
End

EndRem
DescriptionEnd a remark block
Example
Rem
All code between Rem and EndRem is ignored by the BlitzMax compiler.
Print "hello"
End Rem

Print "goodbye"

True
DescriptionConstant integer of value 1
Example
Rem
True is a Constant Integer assigned the value 1.
End Rem

Print "True="+True

If True
	Print "This line will always be executed"
EndIf

If Not True
	Print "This line will never be executed"
EndIf

False
DescriptionConstant integer of value 0
Example
Rem
False is a Constant Integer assigned the value 0.
End Rem

Print "False="+False

If False
	Print "This code will never be executed"
Endif

Pi
DescriptionConstant Pi value: 3.1415926535897932384626433832795
Example
Rem
Pi is a Constant Double assigned the value 3.1415926535897932384626433832795
End Rem

Print "Pi="+Pi

Null
DescriptionGet Default Null value
Example
Rem
Null is a BlitzMax Constant representing an empty Object reference.
End Rem

Type mytype
	Field	atypevariable
End Type

Global a:mytype

if a=null Print "a is uninitialized"
a=new mytype
if a<>null Print "a is initialized"

Byte
DescriptionUnsigned 8 bit integer Type
Example
Rem
Byte is an unsigned 8 bit integer BlitzMax primitive type.
End Rem

Local a:byte

a=512;print "a="+a	'prints 0
a=-1;print "a="+a	'prints 255

Short
DescriptionUnsigned 16 bit integer Type
Example
Rem
Short is an unsigned 16 bit integer BlitzMax primitive type.
End Rem

Local a:short

a=65536;print "a="+a	'prints 0
a=-1;print "a="+a	'prints 65535

Int
DescriptionSigned 32 bit integer Type
Example
Rem
Int is a signed 32 bit integer BlitzMax primitive type.
End Rem

Local a:Int

' the following values all print 0 as BlitzMax "rounds to zero"
' when converting from floating point to integer

a=0.1;print a
a=0.9;print a
a=-0.1;print a
a=-0.9;print a

Long
DescriptionSigned 64 bit integer Type
Example
Rem
Long is a signed 64 bit integer BlitzMax primitive type.
End Rem

Const MAXLONG:Long=$7fffffffffffffff:Long
Const MINLONG:Long=$8000000000000000:Long

Print "A long can have the maximum value of:"+MAXLONG
Print "A long can have the minimum value of:"+MINLONG

Float
Description32 bit Floating point Type
Example
Rem
Float is a 32 bit floating point BlitzMax primitive type.
End Rem

Local a:float

a=1

for i=1 to 8
	print a
	a=a*0.1
next

for i=1 to 8
	a=a*10
	print a
next

Double
Description64 bit floating point Type
Example
Rem
Double is a 64 bit floating point BlitzMax primitive type.
End Rem

Local speedoflight:Double
Local distance:Double
Local seconds:Double

speedoflight=299792458:Double	'meters per second
distance=149597890000:Double	'average distance in meters from earth sun

seconds=distance/speedoflight

Print "Number of seconds for light to travel from earth to sun="+seconds

String
DescriptionString Type
Example
Rem
String is a BlitzMax container type containing a sequence of unicode characters.
End Rem

quote:String=Chr(34)
Print quote+"Hello World!"+quote

Object
DescriptionObject Type
Example
Rem
Object is the base class of all BlitzMax types.

The following function attempts to cast from any object to
the custom type TImage and returns true if the given object
is an instance of TImage or an instance of a &Type derived
from TImage.
End Rem

Function IsImage(obj:Object)
	If TImage(obj) return True
	Return False
End Function

Var
DescriptionComposite Type specifier for 'by reference' types
Example
Rem
Var is a composite type containing a reference to a variable of the 
specified Type.
End Rem

' the following illustrates parsing function parameters by reference

Function ReturnMultiplevalues(a Var,b Var,c Var)
	a=10
	b=20
	c=30
	Return
End Function

Local x,y,z

ReturnMultipleValues(x,y,z)

Print "x="+x	'10
Print "y="+y	'20
Print "z="+z	'30

Ptr
DescriptionComposite Type specifier for pointer types
Example
Rem
Ptr is a composite type containing a pointer to a variable of the specified Type.
End Rem

' the following illustrates the use of traditional c style pointers

Local c[]=[1,2,3,4]
Local p:Int Ptr

p=c
Print "pointer 'p' points to:"+p[0]	'1

p:+1
Print "pointer 'p' points to:"+p[0]	'2

p:+1
Print "pointer 'p' points to:"+p[0]	'3

p:+1
Print "pointer 'p' points to:"+p[0]	'4

If
DescriptionBegin a conditional block.
Example
Rem
If begins a conditional block.
End Rem

If 3<5 Print "3<5"	'single line if

If 5<7				'if block
	Print "5<7"
EndIf

Then
DescriptionOptional separator between the condition and associated code in an If statement.
Example
Rem
Then is an optional separator between the condition and the block of code following an If statement.
End Rem

If 3<5 Then Print "3<5"

Else
DescriptionElse provides the ability For an If Then construct to execute a second block of code when the If condition is False.
Example
Rem
Else provides the ability for an If Then construct to execute a second block of code when the If condition is false.
End Rem

i=3

If i<5 Print "i<5" Else Print "i>=5"	' single line If Else

If i<5			'block style If Else
	Print "i<5"
Else
	Print "i>=5"
EndIf

ElseIf
DescriptionElseIf provides the ability to test and execute a section of code if the initial condition failed.
Example
Rem
ElseIf provides the ability to test and execute a section of code if the initial condition failed.
End Rem

age=Int( Input("How old Are You?") )

If age<13
	Print "You are young"
ElseIf age<20
	Print "You are a teen!"
Else
	Print "You are neither young nor a teen"
EndIf

EndIf
DescriptionMarks the End of an If Then block.
Example
Rem
EndIf marks the end of an If Then block.
End Rem

i=5

If i<10
	Print "i<10"
EndIf

For
DescriptionMarks the start of a loop that uses an iterator to execute a section of code repeatedly.
Example
Rem
For marks the start of a loop that uses an iterator to execute a section of code repeatedly.
End Rem

' print 5 times table

For i=1 to 12
	Print "5*"+i+"="+5*i
Next

To
DescriptionFollowed by a constant which is used to calculate when to exit a For..Next loop.
Example
Rem
Followed by a constant which is used to calculate when to exit a For..Next loop.
End Rem

For i=1 To 5
	print i
Next

Step
DescriptionSpecifies an optional constant that is used to increment the For iterator.
Example
Rem
Specifies an optional constant that is used to increment the For iterator.
End Rem

' count backwards from 10 to 0

For i=10 to 0 step -1
	Print i
Next

Next
DescriptionEnd a For block
Example
Rem
Marks the end of a For section.
End Rem

For i=1 to 5;print i;Next

EachIn
DescriptionIterate through an array or collection
Example
Rem
Specifies a BlitzMax collection type whose values are assigned sequentially to the For iterator.
End Rem

Local a[]=[0,5,12,13,20]

for b=eachin a
	print b
next

While
DescriptionExecute a block of code While a condition is True
Example
Rem
While executes the following section of code repeatedly while a given condition is true.
End Rem

Graphics 640,480
While Not KeyHit(KEY_ESCAPE)	'loop until escape key is pressed
	Cls
	For i=1 to 200
		DrawLine rnd(640),rnd(480),rnd(640),rnd(480)
	Next
	Flip
Wend

Wend
DescriptionEnd a While block
Example
Rem
Wend marks the end of a While section.
End Rem

While i<5
	print i
	i:+1
Wend

EndWhile
DescriptionEnd a While block

Repeat
DescriptionExecute a block of code Until a termination condition is met, or Forever
Example
Rem
Repeat executes the following section of code until a terminating condition is true.
End Rem

Repeat
	print i
	i:+1
Until i=5

Until
DescriptionConditionally continue a Repeat block
Example
Rem
Until marks the end of a Repeat block and is followed by a terminating condition.
End Rem

i=2
Repeat
	print i
	i:*2
Until i>1000000

Forever
DescriptionContinue a Repeat block Forever
Example
Rem
Forever is an alternate ending to a Repeat block that will cause the loop to always repeat.
End Rem

Repeat
	Print i+" Ctrl-C to End!" 
	i:+1
Forever

Select
DescriptionBegin a Select block
Example
Rem
Select begins a block featuring a sequence of multiple comparisons with a single value.
End Rem

a=Int( Input("Enter Your Country Code ") )

Select a
	Case 1
		Print "You are from America"
	Case 44
		Print "You are from the United Kingdom"
	Case 62
		Print "You are from Australia"
	Case 64
		Print "You are from New Zealand"
	Default
		Print "I cannot tell which country you are from"
End Select

EndSelect
DescriptionEnd a Select block
Example
Rem
EndSelect marks the end of a Select block.
End Rem

SeedRnd MilliSecs()

a=Rand(5)

Select a
	Case 1 Print "one"
	Case 2 Print "two"
	Case 3 Print "three"
	Case 4 Print "four"
	Case 5 Print "five"
	Default Print "Program Error"
End Select

Case
DescriptionConditional code inside a Select block
Example
' case.bmx

' Case performs a comparison with the preceeding value(s) and that
' listed in the enclosing Select statement:

a=Int( Input("Enter a number between 1 and 5 ") )

Select a
	Case 1 Print "You think small"
	Case 2 Print "You are even tempered"
	Case 3,4 Print "You are middle of the road"	
	Case 5 Print "You think big"
	Default Print "You are unable to follow instructions"
End Select

Default
DescriptionDefault code inside a Select block
Example
Rem
Default is used in a Select block to mark a code section that is executed if all prior Case statements fail.
End Rem

a$=Input("What is your favorite color?")
a$=lower(a$)	'make sure the answer is lower case

Select a$
	case "yellow" Print "You a bright and breezy"
	case "blue" Print "You are a typical boy"
	case "pink" Print "You are a typical girl"
	default Print "You are quite unique!"
End Select

Exit
DescriptionExit enclosing loop
Example
Rem
Exit causes program flow to exit the enclosing While, Repeat or For loop.
End Rem

Repeat
	Print n
	n:+1
	If n=5 Exit
Forever

Continue
DescriptionContinue execution of enclosing loop
Example
Rem
Continue causes program flow to return to the start of the enclosing While, Repeat or For program loop
End Rem

For i=1 To 20
	If i Mod 2 Continue
	Print i
Next

Const
DescriptionDeclare a constant
Example
Rem
Const defines the preceeding variable declaration as constant.
End Rem

Const ON=TRUE
Const OFF=FALSE

Const TWOPI#=2*PI

print TWOPI

Local
DescriptionDeclare a Local variable
Example
Rem
Local defines a variable as local to the Method or Function it is defined meaning it is automatically released when the function returns.
End Rem

Function TestLocal()
	Local	a
	a=20
	print "a="+a
	Return
End Function

TestLocal
print "a="+a	'prints 0 or if in Strict mode is an error as a is only local to the TestLocal function

Global
DescriptionDeclare a Global variable
Example
Rem
Global defines a variable as Global allowing it be accessed from within Methods and Functions.
End Rem

Global a=20

Function TestGlobal()
	print "a="+a
End Function

TestGlobal
print "a="+a

Field
DescriptionDeclare a Field variable
Example
Rem
Field is used to declare the member variable(s) of a type.
End Rem

Type TVector
	Field	x,y,z
End Type

Local a:TVector=new TVector

a.x=10
a.y=20
a.z=30

Function
DescriptionBegin a Function declaration
Example
Rem
Function marks the beginning of a BlitzMax function declaration.

When a function does not return a value the use of brackets when
calling the function is optional.
End Rem

Function NextArg(a$)
	Local	p
	p=instr(a$,",")
	if p 
		NextArg a$[p..]
		print a$[..p-1]
	else
		print a$
	endif
End Function

NextArg("one,two,three,four")

NextArg "22,25,20"	'look ma, no brackets

EndFunction
DescriptionEnd a Function declaration
Example
Rem
Function marks the end of a BlitzMax function declaration.
End Rem

Function RandomName$()
	local a$[]=["Bob","Joe","Bill"]
	Return a[Rnd(Len a)]
End Function

For i=1 To 5
	Print RandomName$()
Next

Return
DescriptionReturn from a Function
Example
Rem
Return exits a BlitzMax function or method with an optional value.
The type of return value is dictated by the type of the function.
End Rem

Function CrossProduct#(x0#,y0#,z0#,x1#,y1#,z1#)
	Return x0*x1+y0*y1+z0*z1
End Function

Print "(0,1,2)x(2,3,4)="+CrossProduct(0,1,2,2,3,4)

Function LongRand:long()
	Return (rand($80000000,$7fffffff) shl 32)|(rand($80000000,$7fffffff))
End Function

Print "LongRand()="+LongRand()
Print "LongRand()="+LongRand()

Type
DescriptionBegin a user defined Type declaration
Example
Rem
Type marks the beginning of a BlitzMax custom type.

Standard BlitzMax types use a preceeding "T" naming
convention to differentiate themselves from standard
BlitzMax variable names.
End Rem

Type TVector
	Field	x,y,z
End Type

Local a:TVector=new TVector

a.x=10
a.y=20
a.z=30

EndType
DescriptionEnd a user defined Type declaration
Example
Rem
EndType marks the end of a BlitzMax custom type.
End Rem

Type TVector
	Field	x,y,z
End Type

Local a:TVector=new TVector

a.x=10
a.y=20
a.z=30

Extends
DescriptionSpecify user defined Type supertype
Example
Rem
Extends is used in a BlitzMax Type declaration to derive the Type from a specified base class.
End Rem

Type TShape
	Field	xpos,ypos
	Method Draw() Abstract
End Type

Type TCircle extends TShape
	Field	radius
	
	Function Create:TCircle(x,y,r)
		local c:TCircle=new TCircle
		c.xpos=x;c.ypos=y;c.radius=r
		return c
	End Function
	
	Method Draw()
		DrawOval xpos,ypos,radius,radius
	End Method
End Type

Type TRect extends TShape
	Field	width,height
	
	Function Create:TRect(x,y,w,h)
		local r:TRect=new TRect
		r.xpos=x;r.ypos=y;r.width=w;r.height=h
		return r
	End Function
	
	Method Draw()
		DrawRect xpos,ypos,width,height
	End Method
End Type

local 	shapelist:TShape[4]
local	shape:TShape

shapelist[0]=TCircle.Create(200,50,50)
shapelist[1]=TRect.Create(300,50,40,40)
shapelist[2]=TCircle.Create(400,50,50)
shapelist[3]=TRect.Create(200,180,250,20)

graphics 640,480
while not keyhit(KEY_ESCAPE)
	cls
	for shape=eachin shapelist
		shape.draw
	next
	flip
wend
end

Method
DescriptionBegin a Method declaration
Example
Rem
Method marks the beginning of a BlitzMax custom type member function.
End Rem

Type TPoint
	field	x,y

	Method ToString$()
		return x+","+y
	End Method
End Type

a:TPoint=new TPoint
print a.ToString()

EndMethod
DescriptionEnd a Method declaration
Example
Rem
EndMethod marks the end of a BlitzMax Method declaration.
End Rem

Type TPoint
	field	x,y

	Method ToString$()
		return x+","+y
	End Method
End Type

a:TPoint=new TPoint
print a.ToString()

Abstract
DescriptionDenote a Type or Method as Abstract
Example
Rem
A BlitzMax type that contains Abstract methods becomes abstract itself.
Abstract types are used to define interfaces that extending types must 
implement before they can be used to create new instances.

In the following code TShape is an abstract type in that you can not
create a TShape but anything extending a TShape must implement a Draw()
method.
End Rem

Type TShape
	Field	xpos,ypos
	Method Draw() Abstract
End Type

Type TCircle extends TShape
	Field	radius
	
	Function Create:TCircle(x,y,r)
		local c:TCircle=new TCircle
		c.xpos=x;c.ypos=y;c.radius=r
		return c
	End Function
	
	Method Draw()
		DrawOval xpos,ypos,radius,radius
	End Method
End Type

Type TRect extends TShape
	Field	width,height
	
	Function Create:TRect(x,y,w,h)
		local r:TRect=new TRect
		r.xpos=x;r.ypos=y;r.width=w;r.height=h
		return r
	End Function
	
	Method Draw()
		DrawRect xpos,ypos,width,height
	End Method
End Type

local 	shapelist:TShape[4]
local	shape:TShape

shapelist[0]=TCircle.Create(200,50,50)
shapelist[1]=TRect.Create(300,50,40,40)
shapelist[2]=TCircle.Create(400,50,50)
shapelist[3]=TRect.Create(200,180,250,20)

graphics 640,480
while not keyhit(KEY_ESCAPE)
	cls
	for shape=eachin shapelist
		shape.draw
	next
	flip
wend
end

Final
DescriptionDenote a Type or Method as Final
Example
Rem
Final stops methods from being redefined in super classes.
End Rem

Type T1
	Method ToString$() Final
		return "T1"
	end method
End Type

Type T2 extends T1
	method ToString$()	'compile time error "Final methods cannot be overridden"
		return "T2"
	end method
End Type

New
DescriptionCreate an instance of a user defined Type
Example
Rem
New creates a BlitzMax variable of the Type specified.
End Rem

Type MyType
	Field	a,b,c
End Type

Local t:MyType
t=New MyType
t.a=20

print t.a

' if a new method is defined for the type it will also be called

Type MyClass
	Field	a,b,c
	Method New()
		print "Constructor invoked!"
		a=10
	End Method
End Type

Local c:MyClass
c=new MyClass
print c.a

Self
DescriptionReference to this Method's Object instance
Example
Rem
Self is used in BlitzMax Methods to reference the invoking variable.
End Rem

Type MyClass
	Global	count	
	Field	id
	
	Method new()
		id=count
		count:+1
		ClassList.AddLast(self)	'adds this new instance to a global list		
	End Method
End Type

Global ClassList:TList

classlist=new TList

local c:MyClass

c=new MyClass
c=new MyClass
c=new MyClass

for c=eachin ClassList
	print c.id
next

Super
DescriptionReference to the Super Type Object instance
Example
Rem
Super evaluates to Self cast to the method's immediate base class.
End Rem

Type TypeA
	Method Report()
		print "TypeA reporting"
	End Method
End Type

Type TypeB extends TypeA
	Method Report()
		Print "TypeB Reporting"
		super.Report()
	End Method
End Type

b:TypeB=new TypeB
b.Report()

Delete
DescriptionReserved for future expansion
Example
Rem
Reserved for future expansions.
End Rem

Release
DescriptionRelease an integer Object handle
Example
Rem
Release removes the internal reference caused by creating an integer handle to a type.
End Rem

Type MyType
	Field bigmap[1024*1024]
End Type

GCCollect
Print GCMemAlloced()

a=New MyType
GCCollect
Print GCMemAlloced()

Release a
GCCollect
Print GCMemAlloced()

Public
DescriptionPublic makes a Constant, Global variable or Function accessible from outside the current source file (Default)
Example
Rem
Public makes a variable, function or method accessible from outside the current source file (default).
End Rem

Public

Global	Score,Lives,Health

Private

Global	posx,posy,posz

Private
DescriptionPrivate makes a Constant, Global variable or Function only accessible from within the current source file
Example
Rem
Private makes a variable, function or method only accessible from within the 
current source file.
End Rem

Public

Global	Score,Lives,Health

Private

Global	posx,posy,posz

Extern
DescriptionExtern marks the beginning of an external list of Function declarations
Example
Rem
Extern marks the beginning of an external list of function declarations.
End Rem

Extern 
	Function puts( str$z )
	Function my_puts( str$z )="puts"
End Extern

puts "Using clib's put string!"
my_puts "Also using clib's put string!"

EndExtern
DescriptionEndExtern marks the End of an Extern section
Example
Rem
EndExtern marks the end of an Extern section.
End Rem

Extern 
	Function puts( str$z )
End Extern

puts "Using clib's put string!"

Module
DescriptionDeclare Module scope and identifier
Information See the BlitzMax Language Reference for more information on BlitzMax Modules.
Example
Rem
The Module keyword advises the BlitzMax program maker BMK to create a code 
module from the source file.
End Rem

Module PUB.Sequencer

ModuleInfo "Framework: Audio Sequencer for use with FreeAudio"
ModuleInfo "Copyright: Blitz Research Ltd"
ModuleInfo "Author: Simon Armstrong"
ModuleInfo "Version: 1.00"

ModuleInfo
DescriptionDefine Module properties
Example
Rem
ModuleInfo allows properties such as Author and Copyright to be included in a module file.
End Rem

Module PUB.Sequencer

ModuleInfo "Framework: Audio Sequencer for use with FreeAudio"
ModuleInfo "Copyright: Blitz Research Ltd"
ModuleInfo "Author: Simon Armstrong"
ModuleInfo "Version: 1.00"

Incbin
DescriptionEmbed a data file
Example
Rem
IncBin embeds an external data file in a BlitzMax program that can 
then be read using the "incbin::" device name.
End Rem

' code snippet from demos/firepaint/firepaint.bmx

Incbin "stars.png"

Local stars=LoadImage( "incbin::stars.png" )

IncbinPtr
DescriptionGet start address of embedded data file
Example
Rem
IncBinPtr returns a byte pointer to the specified embedded binary file.
End Rem

Incbin "incbinptr.bmx"

Local p:Byte Ptr=IncbinPtr("incbinptr.bmx")
Local bytes=IncbinLen("incbinptr.bmx")

Local s$=String.FromBytes(p,bytes)

Print "StringFromBytes(p,bytes)="+s$

IncbinLen
DescriptionGet length of embedded data file
Example
Rem
IncBinLen returns the size in bytes of the specified embedded binary file.
End Rem

incbin "incbinlen.bmx"

local p:byte ptr=IncBinPtr("incbinlen.bmx")
local bytes=incbinlen("incbinlen.bmx")

local s$=StringFromBytes(p,bytes)

Print "StringFromBytes(p,bytes)="+s$

Include
DescriptionInclude effectively 'inserts' the specified file into the file being compiled.

Framework
DescriptionFramework builds the BlitzMax application with only the Module specified rather than all modules installed.

Import
DescriptionImport declarations from a Module or source file
Example
Rem
:Import specifies the external BlitzMax modules and source files used by the program.
End Rem

Framework BRL.GlMax2D

Import BRL.System

Graphics 640,480,32

While Not KeyHit(KEY_ESCAPE)
	Cls
	DrawText "Minimal 2D App!",0,0
	Flip
Wend

Assert
DescriptionThrow a RuntimeError if a condition is False
Example
Rem
Assert generates a BlitzMax runtime error if the specified condition is false.
End Rem

a=LoadImage("nonexistant image file")
Assert a,"Image Failed to Load"

Goto
DescriptionTransfer program flow to specified label
Example
Rem
Causes program execution to jump to the #label specified.
End Rem

Print "one"
Goto here
Print "two"
#here
Print "three"

Try
DescriptionBegin declaration of a Try block
Example
Rem
Begin declaration of a Try block.
End Rem

Try
	repeat
		a:+1
		print a
		if a>20 throw "chunks"
	forever
Catch a$
	print "caught exception "+a$
EndTry

EndTry
DescriptionEnd declaration of a Try block
Example
Rem
EndTry
EndTry marks the end of a Try block.
End Rem

Catch
DescriptionCatch an exception Object in a Try block
Example
Rem
Catch defines an exception handler following a Try..EndTry Block.
End Rem

Try
	repeat
		a:+1
		print a
		if a>20 throw "chunks"
	forever
Catch a$
	print "caught exception "+a$
EndTry

Throw
DescriptionThrow an exception Object to the enclosing Try block
Example
Rem
Throw generates a BlitzMax exception.
End Rem

Try
	repeat
		a:+1
		print a
		if a>20 throw "chunks"
	forever
Catch a$
	print "caught exception "+a$
EndTry

DefData
DescriptionDefine class BASIC style data
Example
' defdata.bmx

ReadData name$
ReadData age,skill

Print "name="+name+" age="+age+" skill="+skill

DefData "Simon",37,5000

ReadData
DescriptionRead classic BASIC style data

RestoreData
DescriptionRestore classic BASIC style data
Example
' restoredata.bmx

For i=1 To 5
	RestoreData mydata	'reset the data pointer everly loop so we don't read past the end
	ReadData name$,age,skill
	Print "name="+name+" age="+age+" skill="+skill
Next

#mydata	'program label that can be used with the RestoreData command

DefData "Simon",37,5000

And
DescriptionConditional 'And' binary operator
Example
Rem
And is a boolean operator that performs the AND function.
End Rem

For i=1 To 10
	If i>3 And i<6 Print "!" Else Print i
Next

Or
DescriptionConditional 'Or' binary operator
Example
Rem
Or is a boolean operator that performs the OR function.
End Rem

For i=1 To 5
	If i=2 Or i=4 Print "!" Else Print i
Next

Not
DescriptionConditional 'Not' binary operator
Example
Rem
Not is a boolean unary operator that performs the NOT function.
End Rem

Print Not 0			'prints 1 (TRUE)
Print Not 20		'prints 0 (FALSE)

Shl
DescriptionBitwise 'Shift left' binary operator
Example
Rem
Shl is a binary operator that performs the shift to left function.
End Rem

b=1
for i=1 to 32
	print bin(b)
	b=b shl 1
next

Shr
DescriptionBitwise 'Shift right' binary operator
Example
Rem
Shr is a binary operator that performs the shift to right function.
End Rem

b=-1
for i=1 to 32
	print bin(b)
	b=b shr 1
next

Sar
DescriptionBitwise 'Shift arithmetic right' binary operator
Example
Rem
Sar is a binary operator that performs the arithmetic shift to right function.
End Rem

b=$f0f0f0f0
for i=1 to 32
	print bin(b)
	b=b sar 1
next

Len
DescriptionNumber of characters in a String or elements in an array
Example
Rem
Len is a BlitzMax operator that returns the number of elements in a container Type.
End Rem

a$="BlitzMax Rocks"
Print Len a$	'prints 14

Local b[]
Print Len b		'prints 0

b=new Int[20]
Print Len b		'prints 20

Abs
DescriptionNumeric 'absolute value' unary operator
Example
Rem
Abs is a mathematical operator that performs the Absolute function.
End Rem

For f#=-1 To 1 Step 0.125
	Print "Abs "+f+"="+Abs f
Next

Mod
DescriptionNumeric 'modulus' or 'remainder' binary operator
Example
Rem
Mod is a mathematical operator that performs the Modulo function.
End Rem

For i=6 to -6 Step -1
	Print i+" Mod 3="+(i Mod 3)
Next

Sgn
DescriptionNumeric 'sign' unary operator
Example
Rem
Sgn is a mathematical operator that returns the sign of a value.
End Rem

Print Sgn 50	'1
Print Sgn 0		'0
Print Sgn -50	'-1

Min
ReturnsThe lesser of the two numeric arguments
DescriptionNumeric 'minimum' builtin function

Max
ReturnsThe larger of the two numeric arguments
DescriptionNumeric 'maximum' builtin function

Varptr
DescriptionFind the address of a variable
Example
Rem
Varptr returns the address of a variable in system memory.
End Rem

Local a:int
Local p:int ptr

a=20
p=varptr a
print p[0]

SizeOf
DescriptionSize, in bytes, occupied by a variable, string, array or object
Example
Rem
SizeOf returns the number of bytes of system memory used to store the variable.
End Rem

Type MyType
	Field a,b,c
End Type

Local t:MyType
print sizeof t	'prints 12

Local f!
print sizeof f	'prints 8

Local i
print sizeof i	'prints 4

Local b:Byte
print sizeof b	'prints 1

a$="Hello World"
print sizeof a	'prints 22 (unicode characters take 2 bytes each)

Asc
DescriptionGet character value of the first character of a string
Example
Rem
Asc returns the unicode value of the first character of a string.
End Rem

print Asc("A")	'65
Print "A"[0]	'65 - equivalent index style implementation

Chr
DescriptionCreate a string of length 1 with a character code
Example
Rem
Chr returns a String of length 1 containing the unicode character of the value.
End Rem

print Chr(65)	'A