Extracting a reference to a stack

Thierry Douez th.douez at gmail.com
Sat Aug 8 20:43:02 CEST 2015


Here is a regex solution.

and as a bonus, in 3 variants:

on mouseUp
   --            button id 1003 of card id 1002 of stack "stack 2"
   --            of stack "/Users/t/Desktop/stack.livecode"

   put fld "L1" into aLongID

   put theStackOwner( aLongID) into field "L2"

   put theMainStackOwner( aLongID) into field "L3"

   put stackOwners( aLongID) into R

   if R is empty then put "not found" into fld "L4"
   else put item 1 of R &" --- "& item 2 of R into field "L4"
end mouseUp



function theStackOwner pLongID
   if matchText(pLongID, "of stack \x22(.*?)\x22", _1) then return _1
   return "not found"
end theStackOwner

function theMainStackOwner pLongID
   if matchText(pLongID, "of stack \x22([^\x22]*)\x22$", _1) then return _1
   return "not found"
end theMainStackOwner

function stackOwners pLongID
   local REX
   put "(?: of stack \x22([^\x22]*?)\x22)? of stack
\x22([^\x22]*)\x22$" into REX
   if matchText(pLongID, REX, _1, _2) then return _1 &comma& _2
   return empty
end stackOwners

Did a quick test, so it works here,
plus I put the word "stack" in the stack names for a more severe test.

As I hate to write "& quote &" in my code,
\x22 is the ASCII value for the quote char.

Not tested on LC 7 yet.

Regards,

Thierry




------------------------------------------------
Thierry Douez - http://sunny-tdz.com



More information about the use-livecode mailing list