PureObject - PureBasic OOP support

Developed or developing a new product in PureBasic? Tell the world about it.
inc.
Enthusiast
Enthusiast
Posts: 406
Joined: Thu May 06, 2004 4:28 pm
Location: Cologne/GER

Post by inc. »

I will have a look this week as right now im a bit busy.
Check out OOP support for PB here!
inc.
Enthusiast
Enthusiast
Posts: 406
Joined: Thu May 06, 2004 4:28 pm
Location: Cologne/GER

Post by inc. »

SofT MANiAC wrote:
inc. wrote:... you might want to share a part of the code which makes the process crashing.

Thx
ok, lets start...

Dreamotion site: http://www.dreamotion3d.com/site/downloads.php
I went into it and it should work now without bugs when handling multiple Imports also when using IncludePath.
http://www.file-upload.net/download-156 ... e.zip.html
Check out OOP support for PB here!
inc.
Enthusiast
Enthusiast
Posts: 406
Joined: Thu May 06, 2004 4:28 pm
Location: Cologne/GER

Post by inc. »

Update:

- fixed Declare bug in the resulting parser code

http://pb-oop.origo.ethz.ch/download
Last edited by inc. on Thu Jun 25, 2009 11:53 am, edited 1 time in total.
Check out OOP support for PB here!
inc.
Enthusiast
Enthusiast
Posts: 406
Joined: Thu May 06, 2004 4:28 pm
Location: Cologne/GER

Post by inc. »

Update:

- fixed bug of incorrect include file parsing

http://pb-oop.origo.ethz.ch/download
Check out OOP support for PB here!
inc.
Enthusiast
Enthusiast
Posts: 406
Joined: Thu May 06, 2004 4:28 pm
Location: Cologne/GER

Post by inc. »

New Release 1.0rev72:

- 64bit support
http://pb-oop.origo.ethz.ch/download

Please test,
thanks
Check out OOP support for PB here!
aonyn
User
User
Posts: 43
Joined: Tue May 05, 2009 5:20 am

Re: PureObject - PureBasic OOP support

Post by aonyn »

Hi,

I apologize if this is a dumb question, I am not an expert coder by any means.
I am still learning, and feeling comfortable with simple concepts, but trying to progress to more complex concepts.

I have been playing with PB OOP and overall it is beginning to make sense.
However, I am having one problem, returning a value from a method

Here is an example I have been trying to write

Code: Select all

Class vector2D
	vector2D()
	Release()
	
	set(x.f, y.f, test.s)
	getX()
	getY()
	getTestString()
	
	x.f
	y.f
	test.s
EndClass

Procedure vector2D\vector2D()
	; Constructor
EndProcedure

Procedure vector2D\Release()
	; Destructor
EndProcedure

Procedure vector2D\set(x.f, y.f, test.s)
	This\x = x
	This\y = y
	This\test = test
EndProcedure

Procedure.f vector2D\getX()
	x.f = This\x
	Debug x
	ProcedureReturn x
EndProcedure

Procedure.f vector2D\getY()
	y.f = This\y
	Debug y
	ProcedureReturn y
EndProcedure

Procedure.s vector2D\getTestString()
	test$ = This\test
	Debug test$
	ProcedureReturn test$
EndProcedure

*v1.vector2D = NewObject vector2D()
*v1\set(1.0, -1.0, "String Test")
Debug *v1\getX()
Debug *v1\getY()
Debug *v1\getTestString()
I am getting the expected values inside the method, but not after the return, I am instead getting strange results outside the method.
Would someone please help me see what I am doing wrong?
I feel as though I almost grasp how to use PB OOP for simple tasks, except this one very confusing bit.
I am baffled.

Thanks,
Dave
User avatar
Demivec
Addict
Addict
Posts: 4086
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: PureObject - PureBasic OOP support

Post by Demivec »

aonyn wrote:I am getting the expected values inside the method, but not after the return, I am instead getting strange results outside the method.
Would someone please help me see what I am doing wrong?
I feel as though I almost grasp how to use PB OOP for simple tasks, except this one very confusing bit.
I am baffled.
@aonyn: Your code needs to be adapted further. One notable item needed for PureBasic OOP is the defining of an interface for an object's methods. Another point is that the constructor sets up access to the interface.

Here is your code modified to include these points:

Code: Select all


Structure members_Vector2D
  ;virtual table address for function list
  *vtable
  ;all other object data elements
  x.f
  y.f
  test.s
EndStructure

Interface Vector2D_Object
  ;list all functions for object
  Release()
  set(x.f, y.f, test.s)
  getX.f()
  getY.f()
  getTestString.s()
EndInterface

Procedure new_Vector2D()
  ; Constructor
  Protected *object.members_Vector2D = AllocateMemory(SizeOf(members_Vector2D))
  
  If *object
    ;assign vector table address so object can use the functions in the interface
    *object\vtable = ?vector2D_vtable 
    ;assign default values if any
  EndIf
  
  ProcedureReturn *object ;return objects address
EndProcedure

Procedure vector2D_Release(*this.members_Vector2D)
  ; Destructor
  FreeMemory(*this)
  
  ;the return value is designed to be used like this object = object\Release()
  ProcedureReturn #Null 
EndProcedure

Procedure vector2D_set(*this.members_Vector2D, x.f, y.f, test.s)
  *this\x = x
  *this\y = y
  *this\test = test
EndProcedure

Procedure.f vector2D_getX(*this.members_Vector2D)
  x.f = *this\x
  Debug x
  ProcedureReturn x
EndProcedure

Procedure.f vector2D_getY(*this.members_Vector2D)
  y.f = *this\y
  Debug y
  ProcedureReturn y
EndProcedure

Procedure.s vector2D_getTestString(*this.members_Vector2D)
  test$ = *this\test
  Debug test$
  ProcedureReturn test$
EndProcedure


DataSection
  ;vector2D virtual table
  vector2D_vtable:
  Data.i @vector2D_Release()
  Data.i @vector2D_set()
  Data.i @vector2D_getX()
  Data.i @vector2D_getY()
  Data.i @vector2D_getTestString()
EndDataSection

V1.Vector2D_Object = new_Vector2D()
;always make sure return value <> #Null to ensure a valid object was created
If V1 = #Null
  Debug "Object couldn't be created"
  End
EndIf

V1\set(1.0, -1.0, "String Test")
Debug V1\getX()
Debug V1\getY()
Debug V1\getTestString()
Debug V1 = V1\Release()
An additional point is that there is no special variable names required or recognized by PureBasic for any of the functions, variables, or structures (i.e. *this.members_Vector2D could have been written *x.stuff), as long as they are used properly correctly in the code. The ones that were chosen in the example code were to make it easy to understand how the OOP method is implemented (i.e. members_Vector2D is the structure containing the members of the Vector2D object).
aonyn
User
User
Posts: 43
Joined: Tue May 05, 2009 5:20 am

Re: PureObject - PureBasic OOP support

Post by aonyn »

Thanks Demivec,

I am going to study your example and try to get my head around it.
It is certainly a good idea for me to understand how purebasic does OOP with native tools only.

May I ask how it would be done correctly as well with the PB OOP precompiler?
I am not sure, bit it seems to be a bit simpler with the precomiler, and I am hoping if I can learn to understand OOP with OOP style tools, it will then perhaps be easier to understand how it works in native PB, which of course is not made for OOP, so the implementation in native PB is perhaps overly complex, and less intuitive to learn.

I will indeed study what you just gave me Demivec, I do want to understand under the hood as well.
I will post back to let you know how I am doing with it.

Thanks again,
and regards,
Dave
User avatar
Demivec
Addict
Addict
Posts: 4086
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: PureObject - PureBasic OOP support

Post by Demivec »

aonyn wrote:I am going to study your example and try to get my head around it.
It is certainly a good idea for me to understand how purebasic does OOP with native tools only.

May I ask how it would be done correctly as well with the PB OOP precompiler?
I am not sure, bit it seems to be a bit simpler with the precomiler, and I am hoping if I can learn to understand OOP with OOP style tools, it will then perhaps be easier to understand how it works in native PB, which of course is not made for OOP, so the implementation in native PB is perhaps overly complex, and less intuitive to learn.

I will indeed study what you just gave me Demivec, I do want to understand under the hood as well.
I will post back to let you know how I am doing with it.
@aonyn: I'm a little embarrassed. I responded to your question without realizing that the thread dealt with the pre-compiler PureObject. :oops: My comments only reflect doing things natively and not with using PureObject, nor any other pre-compiler. My apologies for being a little off-topic with my response. :oops:
Fred
Administrator
Administrator
Posts: 16619
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: PureObject - PureBasic OOP support

Post by Fred »

Just a shoot in the dark (didn't tried it), but you will may be have to specify the correct return type in your class defnition ?

Code: Select all

Class vector2D
   vector2D()
   Release()
   
   set(x.f, y.f, test.s)
   getX.f()
   getY.f()
   getTestString.s()
   
   x.f
   y.f
   test.s
EndClass
aonyn
User
User
Posts: 43
Joined: Tue May 05, 2009 5:20 am

Re: PureObject - PureBasic OOP support

Post by aonyn »

No worries Demivec,
I appreciate your effort to help.
You could have simply ignored my thread.

Besides that, as I said, I want to learn native OOP style as well, but I am trying to understand the basics with a precompiler first, because it seems to simplify things a bit.

Also, thanks for your reply Fred.
That makes sense, and I will give it a try and post back with my results.

regards,
Dave
aonyn
User
User
Posts: 43
Joined: Tue May 05, 2009 5:20 am

Re: PureObject - PureBasic OOP support

Post by aonyn »

Hi Fred,

Thanks again for your advice.
Perhaps it was a shot in the dark for you, but you were absolutely correct.

I typed my method returns in the class definition, and now my code works as expected.

I feel dumb now, it was so obvious now that you have solved it for me :oops:

Oh, and off topic, but while I have your attention, thanks for your continued development of PureBasic.
I have been trying to learn to code, in various languages, until about a year ago, when I discovered PureBasic.
I was able to learn very basic concepts, but never to the point of feeling comfortable writing my own apps.
Finally in PureBasic, I am confident and comfortable writing apps which I never dreamed of being capable of previously.
And on top of that, I have yet to experience any limits imposed by lacking features in the language.
No regrets purchasing my license, and I will send a donation soon as thanks for the new version you are working on :D

regards,
Dave
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Re: PureObject - PureBasic OOP support

Post by SFSxOI »

@ inc.

Did you know your OOP forum page still shows this:

"This free forum hosting network is under New Management.

We are reviewing all our phpBB version 2 free forum for possible violation.

If you are still viewing this page, please contact us at immediately to get your forum Reviewed and Activated within minutes.

MSN Messenger: freeforum@noeclue.com
Email Support: freeforum@noeclue.com

Any members of this forum can request to get this forum reviewed and activated. When you send either a messenger or email, Please include your full forum URL!

In the meantime, feel free to browse our company online shopping.

Note: New Support Forum will be up and running by tomorrow night!"

?
Last edited by SFSxOI on Sun Jan 03, 2010 2:18 am, edited 1 time in total.
The advantage of a 64 bit operating system over a 32 bit operating system comes down to only being twice the headache.
inc.
Enthusiast
Enthusiast
Posts: 406
Joined: Thu May 06, 2004 4:28 pm
Location: Cologne/GER

Re: PureObject - PureBasic OOP support

Post by inc. »

yeah, i did notice that and I did send a mail but with NO answer or even reopening the specific forum.

I you do know a good free forum space? Seems like http://www.forumer.com/ is worth a look.

But with all honours ... seems almost noone was interested in a specific community dealing with PureObject means PB OOP capabilities.
In times of beeing online, at the end that forum only gots about 15 registrations, so .... I think those topics could be handled in here as well. :-)

But of cource my sig now is updated :-)
Check out OOP support for PB here!
erion
Enthusiast
Enthusiast
Posts: 128
Joined: Sun Jan 24, 2010 11:12 pm

Re: PureObject - PureBasic OOP support

Post by erion »

Hello,
It seems there is a problem with accented characters when using PureObject. For example:

Code: Select all

MessageRequester("","óűáőúéí")
When PureObject is installed in PB's default ide, the preprocessed source's encoding is wrong, which affects accented chars (i.e. when passing them to a function, setting a variable, etc).
With the commandLine compiler (and without PureObject in the IDE) everything works fine.
I thought I'd post it here at first, but please let me know if filling a bug report on your site would be better.
Erion
To see a world in a grain of sand,
And a heaven in a wild flower,
Hold infinity in the palm of your hand,
And eternity in an hour.

- W. B.

Visit my site, also for PureBasic goodies http://erion.tdrealms.com
Post Reply