Class for PB
Posted: Thu May 18, 2017 6:48 pm
At the moment, PB does support Classes/Objects - with Interfaces and structures there are the basic components of object available and with some code you can use them. The only thing that is missing, is a declaration of classes.
I'm only want something, that is technically already possibly!
for declaration:
Because PureBasic is still a Basic-Language, all methods and properties should be public. When a programmer want to indicate, that it should use a method or property, he can start it with a "_". (like for example in Lua)
the method defintion can be done with procedure:
The Class should support (Copy)Constructors and Destructors. The could be define with a \\ to indicate, that this is a special "method" "cFirst\\CopyConstructor(*rightobject)", "cFirst\\Constructor()" and "cFirst\\Destructor".
With AllocateObject(cFirst), CopyObject(*Object) and FreeObject(*Object) to handle object. It would be nice, when instead of AllocateObject(cFirst) a simple cFirst(). would be possible.
Really nice would be a start parameter block
Really, really nice would be, if PB handle the define complete.
The Obj in Test() should be destroyed after the Programm leaves the Procedure (on ProcedureReturn or EndProcedure).
I'm only want something, that is technically already possibly!
for declaration:
Code: Select all
Class cFirst ; Extends Nothing ;)
Method1.i(long1.l, long2.l)
property1.d
EndClass
the method defintion can be done with procedure:
Code: Select all
Procedure.i cFirst\Method1(Long1.l,Long2.l)
SELF\property1=0.5*long1*long2
EndProcedure
With AllocateObject(cFirst), CopyObject(*Object) and FreeObject(*Object) to handle object. It would be nice, when instead of AllocateObject(cFirst) a simple cFirst(). would be possible.
Really nice would be a start parameter block
Code: Select all
Class CSecond (value.d)
pValue.d
EndClass
*obj.CSecond=CSecond(10.5)
debug *obj\pValue ; should return 10.5
Procedure CSecond\\Constructor(value.d)
SELF\pValue=value
ProcedureReturn #true ; Constructor has initialized the Object correct.
EndProcedure
Really, really nice would be, if PB handle the define complete.
Code: Select all
procedure.d Test()
protected obj.CSecond(10.5)
If <something>
ProcedureReturn obj\pValue
EndIf
ProcedureReturn NaN()
EndProcedure