Shop OBEX P1 Docs P2 Docs Learn Events
object nesting — Parallax Forums

object nesting

JavalinJavalin Posts: 892
edited 2006-05-09 17:24 in Propeller 1
Hello!

How far can you nest objects?

I have an application running·one and·two layers deep.· Calls to PUB routines works to the first layer, but calls to the second layer to get first layer values do not return a value.· It looks like the "objectone" layer cannot get and pass back from "objecttwo"

The app structure is as follows:

··········· layerdemo.spin
·············
············· ├──LCDObject.spin
················
················ └──Simple_Serial.spin
·············
············· ├──objectone.spin
················
················ └──objecttwo.spin
·············
············· └──objecttwo.spin


I know this isn't clear so I've attached the project achieve test code.

When the app runs it debugs to a serial LCD (-9600baud) on pin15·and outputs:
"one:125
·one_via_two:0
·two:5"

I've tried increasing the _stack, - am I missing something??

James

PS - SPIN rocks - I love my Propeller!!

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-05-06 22:13
    As you've found out, any object can only see public methods in the object just below it.· Let's say you have:

    Top_Object:
    · -- Layer2
    ····· -- Layer3

    There is no way for Top_Object to use methods in Layer3.· What you can do is create shell methods in Layer2 that call the desired methods in Layer3.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax

    Post Edited (Jon Williams (Parallax)) : 5/6/2006 10:17:33 PM GMT
  • JavalinJavalin Posts: 892
    edited 2006-05-06 22:25
    Hi Jon,

    Ah. I think i've just figured it. I wasn't initializing the object within the object!

    Thanks Jon!

    James
  • JavalinJavalin Posts: 892
    edited 2006-05-06 22:35
    Yep that got it.

    This is working towards an I2C object and libraries. I hope to post tomorrow night!

    Cheers,

    James
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-05-06 22:37
    Cool, you may save me some trouble.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2006-05-08 16:14
    Please explain this nesting further in the Tutorial. I am having to scrambble to piece together what it means.

    Was the question of 'how far?' answered? Just three levels? Or can you extend this quite far?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "When all think alike, no one is thinking very much.' - Walter Lippmann (1889-1974)

    ······································································ Warm regards,····· G. Herzog [noparse][[/noparse]·黃鶴 ]·in Taiwan
  • CJCJ Posts: 470
    edited 2006-05-08 16:24
    shouldn't it be that you can only address methods in objects defined in the calling object's OBJ block. rather than layers and shell methods

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Who says you have to have knowledge to use it?

    I've killed a fly with my bare mind.
  • Paul BakerPaul Baker Posts: 6,351
    edited 2006-05-08 16:44
    Kramer: I could be wrong, but I dont think there is a limit.

    CJ: the issue is trying to access objects declared in the OBJ block of an object declared in a higher OBJ block. For instance, say you declare TV_terminal in your program, the TV_terminal itself declares the TV and graphics objects. Unless you provide special provisions, there is no way for your program to access the methods in the TV or Graphics object.

    I have experienced issues with shelling, for instance I was trying to access the method for drawing a box declared withing the graphics object through the TV_terminal object. I was unable to do so, but was unable to figure out why exactly this was the case. I think it may have to do with accessing data structures several levels down, but this is only a guess.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    1+1=10
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2006-05-09 05:28
    'Shelling' is another new bit of jargon for me. Can anyone provide a concise definition?

    I do understand the Objects seem to talk only to the one above and the one below. In a nutshell, is that it?
    Data seems to be intended to be Public or Private. Variables and such would have to move up and down the line.

    Need to get back to reading the Propeller Docs.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "When all think alike, no one is thinking very much.' - Walter Lippmann (1889-1974)

    ······································································ Warm regards,····· G. Herzog [noparse][[/noparse]·黃鶴 ]·in Taiwan
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-05-09 16:31
    CJ is right; an object only has access to the PUBlic methods in an object that is part of its OBJ definition block.· Methods in objects below this level are not available.· So if we have three objects:

    A
    -- B
    ··· -- C

    "A" can call the PUBlic methods in "B" -- as well as any·PUBlic or PRIvate methods in "A"
    "B" can call the PUBlic methods in "C" -- as well as any·PUBlic or PRIvate methods in "B"
    "C" can call the PUBlic and PRIvate methods in "C"

    It's important to understand that there is no method inheritance per se, i.e., just because "B" can call methods in "C" doesn't mean that "A" (which uses "B") has access to those methods.

    To·me this concept is easier to understand than explain....

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2006-05-09 16:46
    Seems to be clear to me.
    The first sentence may take a bit to fully sink in.

    If that is all I need to know, can I forget about 'shelling'?
    Everyone can disregard my questions about such as it appears muddled.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "When all think alike, no one is thinking very much.' - Walter Lippmann (1889-1974)

    ······································································ Warm regards,····· G. Herzog [noparse][[/noparse]·黃鶴 ]·in Taiwan
  • Paul BakerPaul Baker Posts: 6,351
    edited 2006-05-09 16:49
    Ah sorry, CJ, missed the jist of your question.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    1+1=10
  • JavalinJavalin Posts: 892
    edited 2006-05-09 16:56
    Hi,

    I dont know if this is of any use - but this is the working version of the code that started the thread!

    The fix in my case was when "objectone" runs "objecttwo", it was not being initialized - so the parameter that I was requesting back was of course 0.


    Jon:·
    I posted the i2c object and examples - is it up to your standard?· Did it save you the work?


    James
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-05-09 17:21
    Javelin,

    I looked at your I2C object and believe the are potential issues. Let me finish mine and then we'll compare notes. Don't be alarmed, I could be wrong about what I saw (in a very brief look).

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • JavalinJavalin Posts: 892
    edited 2006-05-09 17:24
    Thanks Jon, Look forward to comparing notes...
Sign In or Register to comment.