Class for PB

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
GPI
PureBasic Expert
PureBasic Expert
Posts: 1394
Joined: Fri Apr 25, 2003 6:41 pm

Class for PB

Post by GPI »

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:

Code: Select all

Class cFirst ; Extends Nothing ;)
  Method1.i(long1.l, long2.l)
  property1.d
EndClass
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:

Code: Select all

Procedure.i cFirst\Method1(Long1.l,Long2.l)
  SELF\property1=0.5*long1*long2
EndProcedure
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

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
The Obj in Test() should be destroyed after the Programm leaves the Procedure (on ProcedureReturn or EndProcedure).
User_Russian
Addict
Addict
Posts: 1443
Joined: Wed Nov 12, 2008 5:01 pm
Location: Russia

Re: Class for PB

Post by User_Russian »

c4s
Addict
Addict
Posts: 1981
Joined: Thu Nov 01, 2007 5:37 pm
Location: Germany

Re: Class for PB

Post by c4s »

I think it would already be a very big advantage if we would be able to instantiate Modules. My feature request with surprisingly PB-like behavior and only minor syntactical changes: "Class Modules" (Create Instances of a Module)
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!
Post Reply