Examples
Some examples of real working Objective-Basic
applications.
EXAMPLE #1: XT a tetris clone for Mac OS X. It and its source codes are included in the Objective-Basic package.
EXAMPLE #2: A larger code example showing most of the syntax elements of Objective-Basic follows here.
EXAMPLE #3: Objective-Basic converts all programs into Objective-C, which is compiled by the default Objective-C compiler of Mac OS X. But reading Objective-Basic programs is much easier than Objective-C programs, without loosing the advantages of Objective-C.

EXAMPLE #1: XT a tetris clone for Mac OS X. It and its
source codes are included in the Objective-Basic package. Download XT with
source codes here.
A larger code example
TetView (included in XT) showing some Cocoa using.
' TetView: view widget to display the
'
gameField in the application window
<h
#import <Cocoa/Cocoa.h>
#import "tet.i"
h>
<c
#import "TetView.h"
c>
Class TetView Inherits NSView
' how the board should be displayed
Dim viewMode As view_mode_t
' opacity of the window background
Dim opacity As Single
' what should be displayed (data array)
Dim boardData AsRef Char
' a reference to the parent window (for shadows)
IBOutlet tetWindow As id
' standard initialization:
' - load sprites from the application bundle
' - initialize instace variables with defaults
Function initWithFrame(frame As NSRect) As id
Dim thisBundle AsRef NSBundle
Dim filePath AsRef NSString
Dim spriteName [@NUM_OF_SPRITES] AsRef NSString = {
@"aqua", @"blue",
@"red", @"green",
@"pink", @"yellow",
@"grey",
}
Dim bannerName [@NUM_OF_BANNERS] AsRef NSString = {
@"pause",
@"gameover",
}
Dim i As Integer
' init parent class
Parent.initWithFrame(frame)
' default is empty-mode
viewMode = @M_NONE
' window is initially transparent
opacity = 0.0
' load stone sprites from the application bundle
' sprites 1..7 are stone elements of different colors
thisBundle = NSBundle.bundleForClass(Me.class())
For i = 0 To @NUM_OF_SPRITES - 1
filePath = thisBundle.pathForResource(r:=spriteName [i], ofType:=@"tiff")
If filePath Then
@stone[i + 1] = NSImage.alloc().initWithContentsOfFile(filePath)
@stone[i + 1].setCacheMode(@NSImageCacheAlways)
End If
Next
' 0 is an empty sprite (no element in window)
@stone[0] = nil
' load banner sprites from the bundle
For i = 0 To @NUM_OF_BANNERS - 1
filePath = thisBundle.pathForResource(r:=bannerName [i], ofType:=@"tiff")
If filePath Then
@banner[i] = NSImage.alloc().initWithContentsOfFile(filePath)
@banner[i + 1].setCacheMode(@NSImageCacheAlways)
End If
Next
Return Me
End Function
' called once by the controller to initialize the pointer to the
' current game data-field to be displayed
Sub initBoardData(data AsRef Char)
boardData = data
End Sub
' the famous drawing routine:
' - erase the depicted window area to transparent color
' - redraw all stone parts in the depicted window area
Sub drawRect(rect As NSRect)
Dim dotRect As NSRect
Dim dot As NSPoint
Dim w As Integer, h As Integer, xl As Integer, xu As Integer,
yl As Integer, yu As Integer, col As Integer
Dim fraction As Single
' compute stone parts to be drawn
xl = rect.origin.x / @T_WIDTH
yl = rect.origin.y / @T_WIDTH
xu = xl + rect.size.width / @T_WIDTH
yu = yl + rect.size.height / @T_WIDTH
' set a clipping rectangle
NSBezierPath.clipRect(rect)
' clear the window
NSColor.clearColor().set()
@NSRectFill (rect)
' draw transparent black background
NSColor.colorWithDeviceRed_(r:=0, green:=0, blue:=0, alpha:=opacity).set()
@NSRectFill (rect)
' setup for drawing the sprites
dotRect.origin.x = 0
dotRect.origin.y = 0
dotRect.size.width = @T_WIDTH
dotRect.size.height = @T_WIDTH
' draw the stones
If viewMode <> @M_NONE Then
fraction = @MODE_FRACTION()
dot.x = xl * @T_WIDTH
For w = xl + 1 To xu
dot.y = yl * @T_WIDTH
For h = yl + 1 To yu
col = @T_ADDR (boardData, w, h)
If col Then
@stone[col].drawAtPoint_(p:=dot, fromRect:=dotRect,_
operation:=@NSCompositeSourceOver, fraction:=fraction)
End If
dot.y = dot.y + @T_WIDTH
Next
dot.x = dot.x + @T_WIDTH
Next
End If
' setup for drawing of the banner
If viewMode = @M_PAUSE Then
dot.x = (@WIN_WIDTH - @P_WIDTH) / 2
dot.y = @WIN_HEIGHT - @P_HEIGHT - 75
dotRect.size.width = @P_WIDTH
dotRect.size.height = @P_HEIGHT
@banner[0].drawAtPoint(p:=dot, fromRect:=dotRect,
operation:=@NSCompositeSourceOver, fraction:=1.0)
Else If viewMode = @M_GAME_OVER
dot.x = (@WIN_WIDTH - @GO_WIDTH) / 2
dot.y = @WIN_HEIGHT - @GO_HEIGHT - 75
dotRect.size.width = @GO_WIDTH
dotRect.size.height = @GO_HEIGHT
@banner[1].drawAtPoint(p:=dot, fromRect:=dotRect,_
operation:=@NSCompositeSourceOver, fraction:=1.0)
End If
tetWindow.invalidateShadow()
End Sub
' returns current display mode
Function getViewMode() As view_mode_t
Return viewMode
End Function
' switch display modes between none, pause,
game and game over mode
Sub setViewMode(mode As view_mode_t)
viewMode = mode
Me.setNeedsDisplay(True)
End Sub
' set the opacity of the application window
background between 0.0 (fully
' transparent) and 1.0 (opaque)
Sub setOpacity(value As Single)
opacity = value
Me.setNeedsDisplay(True)
End Sub
End Class
EXAMPLE #2: A larger code example showing most of the
syntax elements of Objective-Basic follows here.
Class myGreatApplication
Static ll[89, 99] As Integer
Protected bb As Boolean
Public m As Integer
Private qwe AsRef Signed
Private qwe2 AsConstRef Signed
'Private dd AsConstRef d
Const q = 755
Const q2 = "abc"
Const q3 = "eee"
Const q4 = "wwwww"
Const q5 = "sssss"
Const initValue = "Herier"
Enum es
monday = 1
tuesday
wednesday
finit
End Enum
Type sie
'name AsConstRef Char
address As Integer
address2[77] As Integer
sir As Char
v AsRef
v2 AsRef Integer
End Type
Static Function func(j AsRef Char, h AsConstRef Char) AsRef Char
/* j = "12"
h = "321"
Return "0"*/
End Function
Function func2() AsConstRef Char
// Return "0"
End Function
Function func3(i[88] As Integer)
End Function
Function func4(i[] AsRef Char)
End Function
Function func5(i AsRef)
End Function
Sub testmysub(s AsRef NSString)
s = @"geht"
End Sub
Sub init(k As Integer, b As Long) Throws jff
'func3(8)
'func4(8)
Dim x[9] As Integer
Dim x2[9, 70] As Integer
x[7] = x[8]
x[7] = 4
x2[4, 5] = 88
ddd.Func( h := "2", j := "reqe1")
Dim k3[8, 8] As sie
Dim k4[8, 8] As sie
Dim k5[8, 8] As sie
Dim u89 As nix' = k4[zz2.doo( k3[49, 499].address2[48] ), 9].address2[8] + 11
u89 = k3[79, 9].address2[8] + (k4[179, 19].address2[18] - k5[1179, 119].address2[181])
'u89 = k3[79, 9].address2[8] + k4[179, 19].address2[18] + k5[1179, 119].address2[181]
'k3[49, 499].address2[48] = @a.address2() + (b.address2 + c.address2)
Dim r32 As Integer
'r32 = r32 + (3 + 4)
Dim t As sie
Dim t2 As sie
't = t2
't.name = ""
't.address = 99
't.address2[8] = 77
ddd.func(0, "1")
zz2.doSomething(func2(), ddd.func("2", "1"))
/*
Dim rr7 AsRef NSString = NSString.allo9c().init()
Dim r As ZU = ddd.Func( h := "2", j := "reqe1")
Dim r2 As ZU = ddd.func("2", "1")
ddd.func("2", "1")
ddd.func( ddd99.erf("2", "1") , "1")
Dim le As SEL = selector(init:k:zz7)
Dim rr77 AsRef NSString
Dim rr778 AsRef NSString = rr77.al6loc().init()
*/
Dim j1 AsRef Integer
doIt(j1, 88)
Dim rr AsRef NSString = NSString.alloc().init()
Dim rr9 = NSString.alloc() : rr.init()
func2()
Me.func2()
zz2.doSomething("err")
zz2.doSomething(j1, 888)
NSString.doSomething()
NSString.doSomething("d", "7868d")
NSString.doSomething(6, "7868d", 89)
Dim zz AsRef NSString
Dim zz2 AsRef NSString = @"hi"
rr = zz2.init()
rr.openMind()
rr.close("fsf")
doIt(8, 99)
/*
Dim ssds1 AsConstRef Char = __CLASS__
Dim ssds3 AsConstRef Char = __METHOD__
Dim ssds2 AsConstRef Char = __LINE__
Dim ssds4 AsConstRef Char = __FILE__
*/
Const gg2 = "2222"
/*
printf("hi");
Dim ii As Integer = 77
Dim ii2 As Integer = 77
i = 88;
c>
b>
i = 99;
c>*/
//@printf(gg2)
Dim rrr As Long = @strlen(8 ? "hello" : 78) + q3
'Dim r As Long = [[NSString parent] testing]
[circle setColor:[another color]];
[circle setColor:[another color]]
Dim ss AsConstRef Char = gg2
Dim ss2 AsConstRef Char = "t.name"
Const gg = 666
'ss = Left(ss, 3)
Dim sss AsConstRef Char = "e9rror"
Dim sss2 AsRef Char = "error"
Dim c As Char = °"a"
Dim un As Unsigned = 77
Dim si As Signed = 66
Dim nn As Integer = t.address
Dim n As Integer = 8
Dim n2 = 8 As Integer
n = 8 + Inc(n) + t.address
n = Cast(Integer, 8)
n = Cast(AsRef Integer, 8)
n = Cast(AsConstRef Integer, 8)
/*
Dim e As es
e = es.monday
e = es.tuesday*/
Dim d2 As Double = 12.7e10
Dim d1 As Single = 12.43
Dim s1 AsConstRef Char = """Hello"""
Dim a1 As Integer = &HAA
Dim a3 As Integer = &B11001111
Static s2 AsConstRef Char = "Hi"
' Dim k As NSString = @"hey"
n = 99 + 4
n = 99 - 4
n = 99 * 4
n = 99 / 4
n = 99 Mod 4
n = 99 = 4
n = 99 <> 4
n = 99 >= 4
n = 99 <= 4
n = 99 > 4
n = 99 < 4
n = 99 And 4
n = 99 Or 4
n = Not 1
n = 99 ^ 3
n = 99 Xor 3
n = 99 Shl 4
n = 99 Shr 4
'n = "99" Like "4"
n = True AndAlso True
n = True OrElse True
Inc(n)
Dec(n)
'n As Integer = 8 + gg
Dim j5 AsRef
Dim j6
Dim j7 As id
Dim j2 As Integer
Dim j3 AsRef Integer
Dim j4 As Integer
At(j1) = 0
At(j1) = At(j3)
j1 = j3
j5 = j5 + 1
n = SizeOf(n)
j1 = Ref(n)
@printf("doit")
For g As Integer = 1 To 10 Step 4
@printf("z")
@printf("z")
Exit
Iterate
Next
'm = 77
Dim ff
/*
With Me
.m = 99
.m = 99
End With*/
If n > 99 Then
@printf("Hei!")
/*
If m Then
m = 99
m = 99
Endif*/
ElseIf n > 23 Then
n = 333
n = 333
Else
n = 8888
n = 8888
End If
Do
@printf("88")
@printf("88")
Exit
Iterate
Loop While n
Do While n
@printf("99")
@printf("99")
Loop
Select Case n
Case 1
