Please, I do not think it'd be useful seeing in others languages.
If I was not an asshole, I discovered this subject more earlier than today...
All simply... It is the best way to the future. (Maybe is it available today I do not know...)
Else...
, there is an approach of OOP syntax.
Below is a manual header (first code, the second one is one of the available tests). An automatic header already exists but it just grow the availability of items and arguments. Really, the limit is in the internal "functions" of the macros. If we had a free section handled as a datasection but without the syntax ' read.s "" ', etc..., a major part of the problem would be solved.
Code: Select all
;{ Macro }
Macro Quo
"
EndMacro
Macro C_(Object, Method)
CallFunctionFast(Object#\Method, Object)
EndMacro
Macro Inherit(Inherited, Inheriting)
Protected *Inherited.Inherited = *Inheriting\Inherited
EndMacro
Macro RootInherit(Inherited, Inheriting)
Shared Inherited
*Inheriting\Inherited = Inherited
EndMacro
Macro oo
(A,B=,C=,D=,E=,F=,G=,H=,I=,J=,K=,L=,M=,N=,O=,P=,Q=,R=,S=,T=,U=,V=,W=,X=,Y=,Z=,A2=,B2=,C2=,D2=,E2=,F2=)
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
Y
Z
A2
B2
C2
D2
E2
F2
EndMacro
Macro Builder(Obj, M1, C1)
Procedure Obj#M1(*Obj.Obj)
C1
EndProcedure
Obj\M1 = @Obj#M1()
EndMacro
Macro Class(Obj,ArgSet,M1,C1,M2=EndC,C2=,M3=EndC,C3=,M4=EndC,C4=,M5=EndC,C5=,M6=EndC,C6=,M7=EndC,C7=)
Structure Obj
ArgSet
*M1
CompilerIf Quo#M2#Quo <> Quo#EndC#Quo
*M2
CompilerIf Quo#M3#Quo <> Quo#EndC#Quo
*M3
CompilerIf Quo#M4#Quo <> Quo#EndC#Quo
*M4
CompilerIf Quo#M5#Quo <> Quo#EndC#Quo
*M5
CompilerIf Quo#M6#Quo <> Quo#EndC#Quo
*M6
CompilerIf Quo#M7#Quo <> Quo#EndC#Quo
*M7
CompilerEndIf
CompilerEndIf
CompilerEndIf
CompilerEndIf
CompilerEndIf
CompilerEndIf
EndStructure
Define Obj.Obj
Builder(Obj, M1, C1)
CompilerIf Quo#M2#Quo <> Quo#EndC#Quo
Builder(Obj, M2, C2)
CompilerIf Quo#M3#Quo <> Quo#EndC#Quo
Builder(Obj, M3, C3)
CompilerIf Quo#M4#Quo <> Quo#EndC#Quo
Builder(Obj, M4, C4)
CompilerIf Quo#M5#Quo <> Quo#EndC#Quo
Builder(Obj, M5, C5)
CompilerIf Quo#M6#Quo <> Quo#EndC#Quo
Builder(Obj, M6, C6)
CompilerIf Quo#M7#Quo <> Quo#EndC#Quo
Builder(Obj, M7, C7)
CompilerEndIf
CompilerEndIf
CompilerEndIf
CompilerEndIf
CompilerEndIf
CompilerEndIf
EndMacro
Macro MakeObject(Obj, Index) ; In an array
*Obj(Index) = AllocateMemory(SizeOf(Obj) )
CopyMemory(*Obj, *Obj(Index), SizeOf(Obj) )
EndMacro
;}
Code: Select all
;*****************************************************************************************
; ***************************************** CODE ****************************************
;*****************************************************************************************
Class(Device,
oo( Sprite.I,
Keyboard.I,
Mouse.I,
ErrorMessage.S,
),
Init,
oo( *Device\Sprite = InitSprite(),
If *Device\Sprite,
*Device\Keyboard = InitKeyboard(),
*Device\Mouse = InitMouse(),
EndIf,
),
SendError,
oo( MessageRequester("Device error", *Device\ErrorMessage),
End,
),
Check,
oo( If *Device\Sprite = #False,
*Device\ErrorMessage = "Device subsystem is not installed !",
C_(*Device, SendError),
EndIf,
If *Device\Keyboard = #False,
*Device\ErrorMessage = "Keyboard is not installed !",
C_(*Device, SendError),
EndIf,
If *Device\Mouse = #False,
*Device\ErrorMessage = "Mouse is not installed !",
C_(*Device, SendError),
EndIf,
),
)
Class(Desktop,
oo( Current.I,
Quantity.I,
Width.I,
Height.I,
Depth.I,
Frequency.I,
),
Examine,
oo( *Desktop\Quantity = ExamineDesktops(),
*Desktop\Width = DesktopWidth(*Desktop\Current),
*Desktop\Height = DesktopHeight(*Desktop\Current),
*Desktop\Depth = DesktopDepth(*Desktop\Current),
*Desktop\Frequency = DesktopFrequency(*Desktop\Current),
),
)
Class(Screen,
oo( Handle.I,
Width.I,
Height.I,
Depth.I,
Title.S,
Modified.I,
Color.I,
*Desktop,
),
Open,
*Screen\Handle = OpenScreen(*Screen\Width, *Screen\Height, *Screen\Depth, *Screen
\Title),
Close,
oo( If *Screen\Handle,
CloseScreen(),
EndIf,
),
Clear,
oo( *Screen\Modified = #True,
ClearScreen(*Screen\Color),
),
Flip,
oo( If *Screen\Modified = #True,
FlipBuffers(),
EndIf,
),
ImportResolutionFromDesktop,
oo( Inherit(Desktop, Screen),
*Screen\Width = *Desktop\Width,
*Screen\Height = *Desktop\Height,
*Screen\Depth = *Desktop\Depth,
),
)
Class(Processor,
oo( Duration.I,
Clock.I,
),
SetDelay,
Delay(*Processor\Duration),
GetClock,
*Processor\Clock = ElapsedMilliseconds(),
)
#RegionType_Rectangle = 1
#RegionDisplayMode_Direct = 1
Class(Region,
oo( *Parent,
X1.I,
Y1.I,
X2.I,
Y2.I,
Width.I,
Height.I,
Type.I, ; Cf constants
FrontColor.I,
DisplayMode.I, ; Cf constants
*Desktop,
),
CreateDirectRectangle,
oo( *Region\Type = #RegionType_Rectangle,
*Region\DisplayMode = #RegionDisplayMode_Direct,
),
SizeFromDesktop,
oo( Inherit(Desktop, Region),
*Region\X1 = 0,
*Region\Y1 = 0,
*Region\X2 = *Desktop\Width - 1,
*Region\Y2 = *Desktop\Height - 1,
*Region\Width = *Desktop\Width,
*Region\Height = *Desktop\Height,
),
SizeFromParent,
oo( Protected *Parent.REGION,
*Parent = *Region\Parent,
*Region\X1 = *Parent\X1,
*Region\Y1 = *Parent\Y1,
*Region\X2 = *Parent\X2,
*Region\Y2 = *Parent\Y2,
*Region\Width = *Parent\Width,
*Region\Height = *Parent\Height,
),
RandomizeColor,
*Region\FrontColor = RGB(Random(255), Random(255), Random(255) ),
Output,
oo( Select *Region\DisplayMode,
Case #RegionDisplayMode_Direct,
StartDrawing(ScreenOutput() ),
EndSelect,
Select *Region\Type,
Case #RegionType_Rectangle,
Box(*Region\X1, *Region\Y1, *Region\Width, *Region\Height, *Region
\FrontColor),
EndSelect,
StopDrawing(),
),
)
Class(Software,
oo( *Device,
*Desktop,
*Screen,
*Processor,
*Region,
QuitFlag.I,
StandByDelay.I,
StandByClock.I,
),
Init,
oo( RootInherit(Device, Software),
RootInherit(Desktop, Software),
RootInherit(Screen, Software),
RootInherit(Processor, Software),
RootInherit(Region, Software),
),
Start,
oo( C_(*Software, Init),
Inherit(Device, Software),
Inherit(Desktop, Software),
Inherit(Screen, Software),
C_(*Device, Init),
C_(*Device, Check),
*Desktop\Current = 0,
C_(*Desktop, Examine),
*Screen\Desktop = *Desktop,
C_(*Screen, ImportResolutionFromDesktop),
*Screen\Title = "Untitled",
C_(*Screen, Open),
*Screen\Color = RGB(0, 0, 0),
C_(*Screen, Clear),
C_(*Screen, Flip),
),
Finish,
oo( Inherit(Screen, Software),
C_(*Screen, Close),
),
Wait,
oo( Inherit(Processor, Software),
*Processor\Duration = 2000,
C_(*Processor, SetDelay),
),
StandBy,
oo( Inherit(Processor, Software),
If *Software\StandByClock = 0,
*Software\StandByClock = *Processor\Clock + *Software\StandByDelay,
Else,
If *Processor\Clock > *Software\StandByClock,
*Software\QuitFlag = #True,
EndIf,
EndIf,
),
Interface,
oo( C_(*Software, Start),
Inherit(Processor, Software),
Inherit(Region, Software),
Inherit(Desktop, Software),
Inherit(Screen, Software),
*Processor\Duration = 1, ; (milliseconds)
*Software\StandByDelay = 3000, ; (milliseconds)
Dim *Region.REGION(255),
C_(*Region, CreateDirectRectangle),
*Region\Desktop = *Desktop,
C_(*Region, SizeFromDesktop),
C_(*Region, RandomizeColor),
MakeObject(Region, 0),
C_(*Region, CreateDirectRectangle),
*Region\Parent = *Region(0),
C_(*Region, SizeFromParent),
*Region\Height = 32,
C_(*Region, RandomizeColor),
MakeObject(Region, 1),
Repeat,
C_(*Processor, GetClock),
C_(*Processor, SetDelay),
C_(*Software, StandBy),
*Region = *Region(0),
C_(*Region, Output),
*Region = *Region(1),
C_(*Region, Output),
C_(*Screen, Flip),
Until *Software\QuitFlag,
C_(*Software, Finish),
),
)
;
C_(Software, Interface)