Blitz runtime

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.

Function reference

RuntimeError( message$ )   Generate a runtime error

Throws a TRuntimeException.


DebugStop()   Stop program execution and enter debugger

If there is no debugger present, this command is ignored.


DebugLog( message$ )   Write a string to debug log

If there is no debugger present, this command is ignored.


OnEnd( fun() )   Add a function to be called when program ends

OnEnd 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.


ReadStdin$()   Read a string from stdin

Returns: A string read from stdin. The newline terminator, if any, is included in the returned string.


WriteStdout( str$ )   Write a string to stdout

Writes str to stdout and flushes stdout.


WriteStderr( str$ )   Write a string to stderr

Writes str to stderr and flushes stderr.


MemAlloc:Byte Ptr( size )   Allocate memory

Returns: A new block of memory size bytes long


MemFree( mem:Byte Ptr,size )   Free allocated memory

The memory specified by mem must have been previously allocated by MemAlloc or MemExtend.


MemExtend:Byte Ptr( mem:Byte Ptr,size,new_size )   Extend a block of memory

Returns: A new block of memory new_size bytes long

An 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.


MemAlloced()   Memory currently allocated by application

Returns: The amount of memory, in bytes, currently allocated by the application


MemUsage()   Maximum memory allocated by application

Returns: The maximum amount of memory, in bytes, allocated by the application since program startup


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

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

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

GCMalloc:Byte Ptr( size )   Allocate temporary memory from garbage collector

Returns: A block of memory size bytes long

The returned block of memory will be automatically released the next time FlushMem is called. You must not release this memory manually.


Strict   Use strict mode

Strict mode advises the compiler to report as errors all auto defined variables. Strict should appear at the top of your source code before any program code.

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

End   End 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   Begin a remark block

All code between Rem and EndRem is ignored by the BlitzMax compiler.

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   End a remark block

All code between Rem and EndRem is ignored by the BlitzMax compiler.

Example:

Rem
All code between Rem and EndRem is ignored by the BlitzMax compiler.
Print "hello"
End Rem

Print "goodbye"
 

True   Constant 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   Constant 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   Constant double of value 3.1415926535897932384626433832795

Example:

Rem
Pi is a Constant Double assigned the value 3.1415926535897932384626433832795
End Rem

Print "Pi="+Pi

Null   Get Default value

Null returns a different value depending on context. When used in a numeric context, the value 0 is returned. When used in a string or array context, an empty string or array is returned. When used in an object context, the 'null object' is returned.

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   Unsigned 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   Unsigned 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   Signed 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   Signed 64 bit integer type

Float   32 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   64 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   String 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   Object 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   Composite 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   Composite 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 "var p="+Var p	'1

p:+1
Print "var p="+Var p	'2

p:+1
Print "var p="+Var p	'3

p:+1
Print "var p="+Var p	'4

p:+1
Print "var p="+Var p	'and crash...

If   Begin 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   Optional 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   Else 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   ElseIf 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   Marks 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   Marks 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   Followed 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   Specifies 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


EachIn   Iterate 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   Execute 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   End a while block

Example:

Rem
Wend marks the End of a While section.
End Rem

While i<5
	Print i
	i:+1
Wend

Repeat   Execute 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   End 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   End a repeat block

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   Begin 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   End 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   Conditional code inside a select block

Example:

Rem
Case performs a comparison with the preceeding value And that listed in the enclosing Select statement.
End Rem

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 Print "You are middle of the road"	
	Case 4 Print "You win the car!"
	Case 5 Print "You think big"
	Default Print "You are unable to follow instructions"
End Select		

Default   Default 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   Exit enclosing loop

Example:

Rem
Exit causes program flow To Exit the enclosing While, Repeat Or Select code section.
End Rem

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

Continue   Continue execution of enclosing loop

Example:

Rem
Continue causes program flow To Return To the start of the enclosing While, Repeat Or Select code section.
End Rem

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

Const   Declare 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   Declare 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   Declare 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   Declare 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   Begin 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   End 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   Return 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   Begin 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   End 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   Specify 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   Begin 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   End 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   Denote a type or method as abstract

An abstract type cannot be instantiated using New - it is designed to be extended. A type with any abstract methods is itself automatically 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   Denote a type or method as final

Final types can not be extended and final methods can not be overridden. All methods of a final type are themselves automatically 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   Create 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   Self is used in BlitzMax Methods to reference the invoking variable.

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   Super evaluates to Self cast to the method's immediate base class.

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   Reserved for future expansion

Example:

Rem
Reserved For future expansions.
End Rem

Release   Release references to a handle or object

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

a=New MyType
Print MemAlloced()

Release a
FlushMem
Print MemAlloced()
Print a

b:MyType=New MyType
Print MemAlloced()

Release b
FlushMem
Print MemAlloced()

Public   Public 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   Private 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   Extern 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   EndExtern 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   Declare module scope and identifier

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   Define 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   Embed 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   Get 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   Get 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$

Import   Import 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   Throw 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"

FlushMem   Discard all unused memory

Example:

Rem
Causes the BlitzMax garbage collector To remove all unreferenced objects from memory.
End Rem

Type MyType
        Field   bigmap[1024*1024]
End Type

a=New MyType
Print MemAlloced()

Release a
FlushMem
Print MemAlloced()
Print a

b:MyType=New MyType
Print MemAlloced()

Release b
FlushMem
Print MemAlloced()

Goto   Transfer 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   Begin 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   End declaration of a try block

Example:

Rem
EndTry
EndTry marks the End of a Try block.
End Rem

Catch   Catch 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   Throw 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   Define class BASIC style data

ReadData   Read classic BASIC style data

RestoreData   Restore classic BASIC style data

And   Conditional '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   Conditional '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   Conditional '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   Bitwise '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   Bitwise '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   Bitwise 'Shit 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   Number 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   Numeric '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   Numeric '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   Numeric '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   Numeric 'minimum' binary operator

Max   Numeric 'maximum' binary operator

Varptr   Find 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   Bytes of memory 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   Get character value of the first character of a string

Asc returns -1 if string has 0 length.

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   Create 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

Module Information

Modulebrl.blitz
Version 1.01
Author Mark Sibly
License Blitz Shared Source Code
Copyright Blitz Research Ltd
Modserver BRL