Page 1 of 1

Creating a DIFF for livecode stacks (SOLVED)

Posted: Wed May 27, 2015 9:53 am
by MaxV
Hello,
I'm trying to create a DIFF viewer for livecode stacks. I know lcVCS but it's too complex to install and use for my purpose.
I want just to create an XML that represent the livecode stack, then use diff to compare the XML from 2 different livecode stacks.
I reached a good result with mainstacks, I can analyse a mainstack creating a XML file representing all the stack like this: :D

Code: Select all

<stack><rect>105%2C145%2C505%2C545</rect>
<destroyStack>false</destroyStack>
<linkVisitedColor></linkVisitedColor>
<maxWidth>65535</maxWidth>
<textStyle></textStyle>
<visible>true</visible>
<topColor></topColor>
<backPattern></backPattern>
<maxHeight>65535</maxHeight>
<linkHiliteColor></linkHiliteColor>
<editMenus>false</editMenus>
<shadowPattern></shadowPattern>
<topPattern></topPattern>
<iconic>false</iconic>
<cantAbort>false</cantAbort>
<minWidth>32</minWidth>
<liveResizing>true</liveResizing>
<cantModify>false</cantModify>
<backColor></backColor>
<minHeight>32</minHeight>
<foreColor></foreColor>
<linkColor></linkColor>
<hilitePattern></hilitePattern>
<alwaysBuffer>false</alwaysBuffer>
<forePattern></forePattern>
<shadowOffset>4</shadowOffset>
<focusPattern></focusPattern>
<shadowColor></shadowColor>
<systemWindow>false</systemWindow>
<hcAddressing>false</hcAddressing>
<startUpIconic>false</startUpIconic>
<name>Untitled+1</name>
<textSize></textSize>
<windowManagerPlace>false</windowManagerPlace>
<shadow>true</shadow>
<textFont></textFont>
<cantDelete>false</cantDelete>
<scalefactor>1</scalefactor>
<altId>0</altId>
<fullscreen>false</fullscreen>
<icon>0</icon>
<hiliteColor></hiliteColor>
<decorations>title%2Cmenu%2Cminimize%2Cmaximize%2Cclose</decorations>
<behavior></behavior>
<borderColor></borderColor>
<style>toplevel</style>
<externals></externals>
<resizable>true</resizable>
<metal>false</metal>
<underlineLinks></underlineLinks>
<bottomPattern></bottomPattern>
<borderPattern></borderPattern>
<id>1004</id>
<dynamicPaths>false</dynamicPaths>
<windowShape>0</windowShape>
<fullscreenmode></fullscreenmode>
<blendLevel>0</blendLevel>
<destroyWindow>false</destroyWindow>
<focusColor></focusColor>
<menubar></menubar>
<fileName>C%3A%2FDocuments+and+Settings%2Fmax%2FDesktop%2FUntitled+1.livecode</fileName>
<formatForPrinting>false</formatForPrinting>
<stackFiles></stackFiles>
<title></title>
<bottomColor></bottomColor>
<script></script>
<card><backPattern></backPattern>
<borderWidth>2</borderWidth>
<topPattern></topPattern>
<shadowPattern></shadowPattern>
<shadowColor></shadowColor>
<focusColor></focusColor>
<textFont></textFont>
<foreColor></foreColor>
<defaultButton></defaultButton>
<bottomPattern></bottomPattern>
<ink>srcCopy</ink>
<showBorder>false</showBorder>
<name>pippo</name>
<blendLevel>0</blendLevel>
<bottomColor></bottomColor>
<mark>false</mark>
<dontSearch>false</dontSearch>
<shadowOffset>4</shadowOffset>
<focusPattern></focusPattern>
<textSize></textSize>
<altId>0</altId>
<id>1002</id>
<behavior></behavior>
<layer>1</layer>
<cantDelete>false</cantDelete>
<hiliteColor></hiliteColor>
<borderPattern></borderPattern>
<threeD>true</threeD>
<forePattern></forePattern>
<borderColor></borderColor>
<backColor></backColor>
<hilitePattern></hilitePattern>
<topColor></topColor>
<textStyle></textStyle>
<script></script>
<button><rect>115%2C45%2C235%2C165</rect>
<menuHistory>1</menuHistory>
<text></text>
<toolTip></toolTip>
<menuMode></menuMode>
<menuMouseButton>1</menuMouseButton>
<hoverIcon>0</hoverIcon>
<visible>true</visible>
<iconGravity></iconGravity>
<topColor></topColor>
<textStyle></textStyle>
<hilited>false</hilited>
<hiliteIcon>0</hiliteIcon>
<disabledIcon>0</disabledIcon>
<bottomColor></bottomColor>
<borderWidth>2</borderWidth>
<backPattern></backPattern>
<menuLines>5</menuLines>
<shadowPattern></shadowPattern>
<armFill>false</armFill>
<dropShadow></dropShadow>
<topPattern></topPattern>
<label></label>
<backColor></backColor>
<lockLoc>false</lockLoc>
<hilitePattern></hilitePattern>
<foreColor></foreColor>
<cantSelect>false</cantSelect>
<autoArm>false</autoArm>
<accelKey></accelKey>
<forePattern></forePattern>
<showIcon>false</showIcon>
<layerMode>static</layerMode>
<visitedIcon>0</visitedIcon>
<shadowOffset>4</shadowOffset>
<titleWidth>0</titleWidth>
<showName>true</showName>
<shadowColor></shadowColor>
<showFocusBorder>true</showFocusBorder>
<focusPattern></focusPattern>
<opaque>true</opaque>
<showHilite>false</showHilite>
<innerGlow></innerGlow>
<sharedHilite>true</sharedHilite>
<accelText></accelText>
<ink>srcCopy</ink>
<labelWidth>0</labelWidth>
<showBorder>true</showBorder>
<name>Button</name>
<textSize></textSize>
<shadow>false</shadow>
<textFont></textFont>
<disabled>false</disabled>
<colorOverlay></colorOverlay>
<default>false</default>
<altId>0</altId>
<icon>0</icon>
<armed>false</armed>
<hiliteColor></hiliteColor>
<behavior></behavior>
<borderColor></borderColor>
<style>standard</style>
<family>0</family>
<innerShadow></innerShadow>
<hiliteBorder>true</hiliteBorder>
<bottomPattern></bottomPattern>
<borderPattern></borderPattern>
<outerGlow></outerGlow>
<id>1004</id>
<menuName></menuName>
<blendLevel>0</blendLevel>
<armBorder>true</armBorder>
<mnemonic>0</mnemonic>
<hiliteFill>false</hiliteFill>
<accelMods></accelMods>
<traversalOn>false</traversalOn>
<focusColor></focusColor>
<armedIcon>0</armedIcon>
<textAlign>center</textAlign>
<autoHilite>true</autoHilite>
<threeD>true</threeD>
<margins>4</margins>
<layer>1</layer>
<script>on+mouseEnter%0D%0A+++lock+screen%0D%0A+++put+the+loc+of+me+into+temp%0D%0A+++set+the+width+of+me+to+150%0D%0A+++set+the+height+of+me+to+150%0D%0A+++set+the+loc+of+me+to+temp%0D%0A+++unlock+screen%0D%0Aend+mouseEnter%0D%0A%0D%0Aon+mouseLeave%0D%0A+++lock+screen%0D%0A+++put+the+loc+of+me+into+temp%0D%0A+++set+the+width+of+me+to+120%0D%0A+++set+the+height+of+me+to+120%0D%0A+++set+the+loc+of+me+to+temp%0D%0A+++unlock+screen%0D%0Aend+mouseLeave%0D%0A</script>
</button>
</card>
</stack>
My problem is with substacks. If I analyse a remote stack, I can use this code:

Code: Select all

put the rect of button 1 of card 1 of stack "C:/Documents and Settings/max/Desktop/Untitled 1.livecode"
no problem, the remote stack is not opened.
But if I try to analyse the substacks, stack is opened and something goes wrong. I noticed that substack are numbered starting from 1, so the first substack is:

Code: Select all

 stack 1 of stack "C:/Documents and Settings/max/Desktop/Untitled 1.livecode"
So I use this code:

Code: Select all

put the rect of button 1 of card 1 of stack 1 of stack "C:/Documents and Settings/max/Desktop/Untitled 1.livecode"
but this way stack remote is opened and reopened may times, a purge request appears continuously and it's a mess.
What is the correct code to analyse properties of substacks? :?:

Re: Creating a DIFF for livecode stacks

Posted: Wed May 27, 2015 2:39 pm
by dunbarx
Well, I thought something like this would work:

Code: Select all

on mouseUp
   lock screen
   go stack "yourStackPathName"
   put the name of btn 1 of  stack "yourStackPathName" --or any request for info
   close  stack "yourStackPathName"
end mouseUp
And it does, but the window of the stack flashes for a few ticks, which is annoying. I guess lock screen only applies to the current window? And when you open another an entirely new environment appears, where the screen is no longer locked? The dictionary says"
A handler may need to open a stack and then close it before the handler is completed, or to move or change the appearance of a number of objects on the screen. If the screen is locked before these changes occur, the user does not see the changes happen on screen. Locking the screen can prevent user confusion or unsightly screen flashing. It also increases the speed of the handler, since LiveCode does not have to redraw all the intermediate states of the screen.
Which contradicts what I see, Implying that the "screen" is the screen, and not just windows on the screen.

Craig

Re: Creating a DIFF for livecode stacks

Posted: Wed May 27, 2015 4:36 pm
by jacque
Right, it only locks the current window. The docs are only correct if you open the new stack in the same window. I'm not sure there's a way to prevent the OS from flashing on window creation, at least on Macs.

Re: Creating a DIFF for livecode stacks

Posted: Wed May 27, 2015 6:24 pm
by FourthWorld
I've been working on a diff tool that works on native stack files, and I found I could get the info I need from two versions of a stack file within the same LiveCode session if I use "delete stack <mainstackname>" after I'm done with each.

On the latter it's important to note that "delete stack" does two very different things depending on whether it's used on a mainstack or a substack: with a mainstack it merely removes it from memory, but when used on a substack it deletes the substack from the stack file.

I wish they'd clean up the syntax and provide two different commands for those very different operations, but for now we just need to be very careful in how we use them.

Re: Creating a DIFF for livecode stacks

Posted: Wed May 27, 2015 6:56 pm
by FourthWorld
Reviewing the earlier comments here about "lock screen", it may be helpful to note that it's not necessary to "open" or "go" to a stack to retrieve all data from it. Scripts and all other properties can be obtained by referencing the stack file, without explicitly opening it, e.g.:

Code: Select all

get the rect of stack "SomeSubstack" of stack "/home/user/somefolder/somestack.livecode"
It's not merely faster to work without opening, but much simpler to code for, allowing you to obtain all information from a stack file without every risking triggering any openStack, openCard, etc. scripts. It'll still load the stack file into memory, though, so you'll still need to "delete" the mainstack to remove it from memory when you're done with it.

Re: Creating a DIFF for livecode stacks

Posted: Wed May 27, 2015 7:13 pm
by dunbarx
@Richard.

Absolutely.

@Max.

I forget why I thought you wanted to navigate to the other stack. But in any case, in retrieving any property, I see no stack opened (if you simply provide a pathway reference) nor a substack, if you simply provide a name or number. This applies to any control on those stacks as well. How do you know the substack opens? Do you see it? Is it in "the stacks"?

Craig

Re: Creating a DIFF for livecode stacks

Posted: Thu May 28, 2015 2:35 pm
by MaxV
I get this:
Image

Re: Creating a DIFF for livecode stacks

Posted: Thu May 28, 2015 3:03 pm
by FourthWorld
MaxV wrote:I get this:
Image
Under what circumstances?

Re: Creating a DIFF for livecode stacks (solved)

Posted: Thu May 28, 2015 5:05 pm
by MaxV
Ok, I found the problem. :D
If I use the message box all works fine, this code doesn't open or load stack/substacks:

########CODE#######
put the number of controls of card 1 of stack "Untitled 3" of stack "C:/Documents and Settings/max/Desktop/Untitled 1.livecode"
#####END OF CODE#####

but in my program load the stack and substacks, creating the message I posted.
After may try and error I found the following differences.
This code works but loads substacks generating a preogram and purge requests on screen: :evil:

########CODE#######
put "untitled 3" into mysusbstack
put "C:/Documents and Settings/max/Desktop/Untitled 1.livecode" into mymainstack
put the number of controls of card 1 of stack mysusbstack of stack mymainstack
#####END OF CODE#####

On the contrary this works great, without loading any stack: :twisted:

########CODE#######
put "untitled 3" into mysusbstack
put "C:/Documents and Settings/max/Desktop/Untitled 1.livecode" into mymainstack
do "put the number of controls of card 1 of stack " & quote & mysusbstack & quote & " of stack " & quote & mymainstack & quote
#####END OF CODE#####

I suppose it's related how livecode intepretes commands and variables.

Re: Creating a DIFF for livecode stacks (SOLVED)

Posted: Thu May 28, 2015 6:35 pm
by FourthWorld
If using "do" makes a difference that may be a bug, since the evaluated expression should ideally be the same whether dynamically assembled with "do" or inline.

Are you calling "delete stack <mainstackfile>" for each version of the stack file after you're done obtaining info from it?

Re: Creating a DIFF for livecode stacks (SOLVED)

Posted: Thu May 28, 2015 8:51 pm
by MaxV
FourthWorld wrote: Are you calling "delete stack <mainstackfile>" for each version of the stack file after you're done obtaining info from it?
No, I don't. Because it's not really loaded by livecode. 8)

Re: Creating a DIFF for livecode stacks (SOLVED)

Posted: Thu May 28, 2015 9:10 pm
by FourthWorld
MaxV wrote:
FourthWorld wrote: Are you calling "delete stack <mainstackfile>" for each version of the stack file after you're done obtaining info from it?
No, I don't. Because it's not really loaded by livecode. 8)
When you see LiveCode telling you a stack is loaded, it may not be lying. :)

Whenever any stack file is queried, the stack file contents are loaded into RAM and unpacked so that the specific elements you're looking for can be obtained. The difference between querying properties and using "go" or "open" is that the latter will also trigger system messages. But either means of accessing the file will cause it to be loaded.

Thankfully, LiveCode also provides a way to unload the contents of a stack file, with the "delete stack" command (though unfortunately it requires us to be careful to do that only on mainstacks and not substacks, for the reasons noted earlier).

I do this a lot. Try it, and let me know if it doesn't resolve the issue.