Extracting a reference to a stack

Richard Gaskin ambassador at fourthworld.com
Sat Aug 8 20:37:24 EDT 2015


David Bovill wrote:

 > Richard Gaskin wrote:
 > >> function ObjectStack pObj
 > >>    return char (offset(" of stack ", pObj)+4) to -1 of pObj
 > >> end ObjectStack
 >
 > The test case would be "this is a stack of rubish" as a substack -
 > that would break your code?

It would have to be "this is a of stack of rubbish" - but even then it 
wouldn't break since the long ID of the object would be:

   button id 1003 of card id 1002 of stack "this is of stack of rubbish"
   of stack "/Users/t/Desktop/stack.livecode"

...in which the first occurrence of " of stack " is the one we want.

We could break it by changing the use case: instead of requiring long 
IDs (I rarely anything else) we might pass in a long name, in which a 
button might have a name that includes " of stack ".

But as soon as we allow other forms of object references to be passed in 
we're probably going to want to convert those to long IDs anyway.  And 
since we can't guarantee the object reference is valid we'd probably 
need to add a try structure there as well:

function ObjectStack pObj
    try
      put the long id of pObj into pObj
    catch tErr
      throw "Error in call to ObjectStack: invalid object reference"
    end try
    return char (offset(" of stack ", pObj)+4) to -1 of pObj
end ObjectStack

Any other edge cases that should be accounted for?

-- 
  Richard Gaskin
  Fourth World Systems
  Software Design and Development for the Desktop, Mobile, and the Web
  ____________________________________________________________________
  Ambassador at FourthWorld.com                http://www.FourthWorld.com




More information about the use-livecode mailing list