PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Some new OOP bugs

Code:

#class TParent
public(
a$
);

private(
c$
);

c$ = 0;

public proc doTest()//this procedure is overridden in the child
a$ = 10;
showMessage("This is the parent proc");
end;

private proc PrivateProc()
showMessage("Private proc call");
end;

private proc testSelfPrivateCall()
self.PrivateProc();
end;

private func testSelf()
self.doTest();//call our virtual function
c$++;
if (c$ == 2)
return (false);
else
return (true);
end;
end;


public proc generalTest()
while (testSelf())
end;
end;


#endclass


#class TParent TChild

public proc doTest()
#inherited doTest();//call the parent's proc
a$ = 20;
showMessage("This is the child proc");
end;

#endclass


proc main
#object TChild obj$;

//First bug - the private proc shoud be available for self$ variable
obj.TestSelfPrivateCall();

//Second bug - self$ variable was missed somewhere in the depths of memory :)
obj.generalTest();

end;


Btw, this is the example of how we can make some kind of virtual(c++) functions in PPL.
Don't use the self. statement, to call a private method inside a class just use the method's name.

proc class.test
self.method; // is not supported in PPL.
end;

proc class.test
method; // is though.
end;
Code:
#class TParent
public(
a$
);

private(
c$
);

c$ = 0;

public proc doTest()//this procedure is overridden in the child
a$ = 10;
showMessage("This is the parent proc");
end;

private proc PrivateProc()
showMessage("Private proc call");
end;

public proc testSelfPrivateCall()
PrivateProc();
end;

private func testSelf()
doTest();//call our virtual function
c$++;
if (c$ == 2)
return (false);
else
return (true);
end;
end;


public proc generalTest()
while (testSelf())
end;
end;


#endclass


#class TParent TChild

public proc doTest()
#inherited doTest();//call the parent's proc
a$ = 20;
showMessage("This is the child proc");
end;

#endclass


proc main
#object TChild obj$;

//First bug - the private proc shoud be available for self$ variable
obj.TestSelfPrivateCall();

//Second bug - self$ variable was missed somewhere in the depths of memory
obj.generalTest();

end;


This code works well with the new version of PPL.
Hi Kornalius,
You misunderstood a problem a bit:
As you can see in main proc we inited the Tchild object, and then we call procedure of parent object which calls doTest(),so the Tchild.doTest() proc should be called instead of Tparent.doTest, thats why i used self$ to make ppl know which type of object now in use and to call right procedure, what is more, it worked okay except that example.
Ok, I got it, I will fix it next week for the next release.
Here is the another few questions/troubles/bugs:
Code:

#class Tobj
private(
prop$,
owner$
);
private nproc Create
prop$ = -1;
end;

public proc SetProp(p$)
prop$ = p$;
end;

public func getProp
return (prop$);
end;

public proc SetOwner(o$)
owner$=o$;
end;

public func getOwner()
return(owner$);
end;
#endClass



#class TObjContainer
public(
objects$
);

private nproc Create
list(objects$);
end;

public proc AddObj(obj$)
&bufObj;$=obj$;//See the first question

//See the second question:
//here we set the owner of object
//this way it works and we store the real address of self$ in Tobj.owner
//However any other way (as it mentioned in question 2 it doesn work)
pt$=&self;$;
bufObj.setOwner(pt$);
add(objects$, obj$);
end;

public proc SetProperties(p$)
foreach (objects$)
&bufObj;$ = objects$;//see the first question
bufObj.setProp(p$);
end;
end;

public proc ShowProperties()
s$ = "";
foreach (objects$)
&bufObj;$ = objects$; //see the first question
s$ += " " + str(bufObj.getProp());
end;
showMessage(s$);
end;

public proc showObjAddresses()//shows the addresses of objects
s$ = "";
foreach (objects$)
s$ += " " + str(objects$);//I suppose, here we store integer value of object pointer
end;
showMessage(s$);
end;

public proc showObjOwners()//shows the addresses of objects owners
s$ = "";
foreach (objects$)
&bufObj;$ = objects$; //see the first question
s$ += " " + str(bufObj.getOwner());
end;
showMessage(s$);
end;

#endclass

proc main
#object Tobj o1$();
#object Tobj o2$();
#object Tobj o3$();
o1.setProp(10);
o2.setProp(20);
o3.setProp(30);

//Lets see the actual objects addresses:
s$="";
s$+=" "+str(&o1;$);
s$+=" "+str(&o2;$);
s$+=" "+str(&o3;$);
showMessage(s$);

//THE FIRST QUESTION:
//bufObj$ - global variable which is used to convert
//object address to the object variable itself (as mySprite$ variable in gameApI)
//Can I do it this way ???????????????? Is it right ???
TObj(bufObj$);
global(bufObj$);

#object TObjContainer cont$;

//THE SECOND QUESTION/TROUBLE:
//Now I want to add some objects to my container
//so the container have to store just the objects addresses

/*
This way it doesnt work - when we want to see objects addresses (in showObjAddress proc)
we only see "Tobj"

cont.addObj(&o1;$);
cont.addObj(&o2;$);
cont.addObj(&o3;$);
*/

/*
And This way it shows the same
cont.addObj(addr(o1$));
cont.addObj(addr(o2$));
cont.addObj(addr(o3$));
*/

//The only way it shows real addresses of objects is that:
pt$=&o1;$;
cont.addObj(pt$);
pt$=&o2;$;
cont.addObj(pt$);
pt$=&o3;$;
cont.addObj(pt$);

/*
However if I'll write this (slightly changed version):
cont.addObj(&o1;$);
pt$=&o2;$;
cont.addObj(pt$);
pt$=&o3;$;
cont.addObj(pt$);

it again doest work at all.
*/

cont.showProperties();
cont.showObjAddresses();
cont.showObjOwners();
end;

Hope I describe the problem correctly.
This was my post, sorry
One of the reason why you don't see the object address is because an object is made of two values. A string containing the object class name and a value containing the object's variables address. When you do a ShowMessage, the first value is taken (string in this case). You might need to use int() to use the address instead of the string value.

I will try your code early next week and fix the whole thing.

Thanks again for thoroughly testing the object-oriented engine, I really appreciate it and it helps me a great deal.
Hi,

I have fixed the problem. It was the add() function not flagging the list element as an object type.

The following code works perfectly with the newest version of PPL:

Code:
#class Tobj
private(
prop$,
owner$
);
private nproc Create
prop$ = -1;
end;

public proc SetProp(p$)
prop$ = p$;
end;

public func getProp
return (prop$);
end;

public proc SetOwner(o$)
owner$ = o$;
end;

public func getOwner()
return (owner$);
end;
#endClass



#class TObjContainer
public(
objects$
);

private nproc Create
list(objects$);
end;

public proc AddObj(obj$)
&bufObj;$ = obj$; //See the first question

//See the second question:
//here we set the owner of object
//this way it works and we store the real address of self$ in Tobj.owner
//However any other way (as it mentioned in question 2 it doesn work)
pt$ = &self;$;
bufObj.setOwner(pt$);
add(objects$, obj$);
end;

public proc SetProperties(p$)
foreach (objects$)
&bufObj;$ = objects$; //see the first question
bufObj.setProp(p$);
end;
end;

public proc ShowProperties()
s$ = "";
foreach (objects$)
&bufObj;$ = objects$; //see the first question
s$ += " " + str(bufObj.getProp());
end;
showMessage(s$);
end;

public proc showObjAddresses() //shows the addresses of objects
s$ = "";
foreach (objects$)
s$ += " " + &objects;$; //I suppose, here we store integer value of object pointer
end;
showMessage(s$);
end;

public proc showObjOwners() //shows the addresses of objects owners
s$ = "";
foreach (objects$)
&bufObj;$ = objects$; //see the first question
s$ += " " + str(bufObj.getOwner());
end;
showMessage(s$);
end;

#endclass

proc main
#object Tobj o1$();
#object Tobj o2$();
#object Tobj o3$();
o1.setProp(10);
o2.setProp(20);
o3.setProp(30);

//Lets see the actual objects addresses:
s$ = "";
s$ += " " + str(&o1;$);
s$ += " " + str(&o2;$);
s$ += " " + str(&o3;$);
showMessage(s$);

//THE FIRST QUESTION:
//bufObj$ - global variable which is used to convert
//object address to the object variable itself (as mySprite$ variable in gameApI)
//Can I do it this way ???????????????? Is it right ???
TObj(bufObj$);
global(bufObj$);

#object TObjContainer cont$;

//THE SECOND QUESTION/TROUBLE:
//Now I want to add some objects to my container
//so the container have to store just the objects addresses


//This way it doesnt work - when we want to see objects addresses (in showObjAddress proc)
//we only see "Tobj"

cont.addObj(&o1;$);
cont.addObj(&o2;$);
cont.addObj(&o3;$);


/*
And This way it shows the same
cont.addObj(addr(o1$));
cont.addObj(addr(o2$));
cont.addObj(addr(o3$));
*/

//The only way it shows real addresses of objects is that:
/*pt$ = &o1;$;
cont.addObj(pt$);
pt$ = &o2;$;
cont.addObj(pt$);
pt$ = &o3;$;
cont.addObj(pt$);*/

/*
However if I'll write this (slightly changed version):
cont.addObj(&o1;$);
pt$=&o2;$;
cont.addObj(pt$);
pt$=&o3;$;
cont.addObj(pt$);

it again doest work at all.
*/

cont.showProperties();
cont.showObjAddresses();
cont.showObjOwners();
end;
Thanks Kornalius, and what about the first bug in this topic ( about self.method calls)?
It was fixed partly, I just fixed the self.call() syntax to work properly now.