Re: How to loop through stacks with same name?

2023-04-04 Thread J. Landman Gay via use-livecode
Are you opening all the same-named stacks at once? LC warns that this 
produces unreliable results and should be avoided. The "delete stack" 
command does work from a script, but if there are several open with the 
same name there's no telling what the engine will do. The normal way to 
handle this is to only open one, delete it when done with it, and then open 
the next.


But if it is necessary for some reason to have multiple same-named stacks 
open then check the mainstacks rather than the openstacks. The mainstacks 
function should report all stacks in memory, not just the ones that are 
open on screen.


Untested, but try this:

repeat until "stackName" is not in the mainstacks -- whatever the duplicate 
stack name is

delete stack "stackName"
end repeat

It might work. Also, check your LC preferences in the Files and Memory 
pane. Tick the option to close the stack even if its deleteStack property 
is false. That should allow you to close any stack and remove it from 
memory just with the close box.


--
Jacqueline Landman Gay | jac...@hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
On April 4, 2023 9:25:08 AM Håkan Liljegren via use-livecode 
 wrote:


When my students turn in their assignments all their individual stacks 
usually have the same name. If I try to loop through all of them there 
seems to be no way to close one stack and move on to the next one (with the 
same name) without getting the dialog asking if I want to save, purge or 
cancel the previous stack?!





___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Sockets (again)

2023-04-04 Thread Phil Davis via use-livecode

Bob -

Don't use EOF. It's broken since forever ago.

I've done both of the following methods with success:

-- either --

End your data stream with a CR, and then on the receiving end "read from 
socket XYZ for 1 line". This assumes that the data stream itself doesn't 
contain any CRs. I normally base64-encode the data stream, then replace 
CR with empty in the encoded string. This doesn't interfere with 
base64Decoding on the receiving end - it'll still work fine.


-- or --

Make line 1 of your data stream an integer that is the number of bytes 
in line 2 of your data stream

Make line 2 of your data stream the data you want to send

Then on the receiving end, do a two-step:
- read from socket XYZ for 1 line
- put it into tDataLength
- read from socket XYZ for tDataLength bytes


That's all I got :-)
Phil Davis



On 4/4/23 1:47 PM, Bob Sneidar via use-livecode wrote:

I have sockets working in my File Server Agent, but only using non-blocking calls, that is using 
"with message". Removing the "with message" bit does not return any response 
from the server agent.

For instance I send a payload using
write payload to socket tSocket with message "messageReceived"
The messageReceived handler gets triggered, and I can then
read from socket tSocket until EOF -- or other delimiter
it will then contain the response from the File Server Agent.

If however I use
write payload to socket tSocket -- blocking
read from socket tSocket until EOF -- or some other delimiter doesn't matter

the call times out and nothing ends up in the it or result variables.

I can (and have) made the non-blocking method work, but that means I have to 
send all the files I want to transfer all at once, because if I send them one 
at a time, I need to know if the last transfer succeeded before continuing.

Does anyone have an example of a blocking socket server? The example in 
Livecode Lessons really only focuses on non-blocking calls.

Bob S


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode



--
Phil Davis
(503) 307-4363


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Sockets (again)

2023-04-04 Thread Bob Sneidar via use-livecode
I have sockets working in my File Server Agent, but only using non-blocking 
calls, that is using "with message". Removing the "with message" bit does not 
return any response from the server agent. 

For instance I send a payload using 
write payload to socket tSocket with message "messageReceived" 
The messageReceived handler gets triggered, and I can then 
read from socket tSocket until EOF -- or other delimiter
it will then contain the response from the File Server Agent. 

If however I use 
write payload to socket tSocket -- blocking
read from socket tSocket until EOF -- or some other delimiter doesn't matter

the call times out and nothing ends up in the it or result variables. 

I can (and have) made the non-blocking method work, but that means I have to 
send all the files I want to transfer all at once, because if I send them one 
at a time, I need to know if the last transfer succeeded before continuing. 

Does anyone have an example of a blocking socket server? The example in 
Livecode Lessons really only focuses on non-blocking calls. 

Bob S


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: How to loop through stacks with same name?

2023-04-04 Thread Håkan Liljegren via use-livecode
Thanks for the input, digging further…

If I run the following code:
   put 0 into tCount
   delete tStackID
   put revLoadedStacks() into tStackList
   repeat while tStack is among the lines of tStackList
  add 1 to tCount
  delete stack tStack
  wait 100 milliseconds with messages
  put revLoadedStacks() into tStackList
   end repeat
   put "Looped " & tCount & " times" & CR & tStackList

I get the output “Looped 0 times” followed by a list without tStack but If I 
then run ‘put revLoadedStacks()' from a button or in the message box the stack 
is back again! My very unprofessional guess is that this reappearance of the 
stack might be the same problems that sometimes causes the infinite 
save-purge-cancel loop that sometimes occurs in the IDE.

If I on the other hand run ‘delete stack “mystack”’ in the message box. The 
stack is gone and never reappears!


> On 4 Apr 2023, at 17:18, Paul Dupuis via use-livecode 
>  wrote:
> 
> I believe there is a IDE handler you can call to unload a stack - something 
> like "revUnloadStack" or similar, but I do not recall the exact API name.
> 
> Hopefully, some one else on the list has the exact API details. 
> Alternatively, contact supp...@livecode.com and ask what the IDE API is to 
> unload a stack.
> 
> 
> 
> On 4/4/2023 10:22 AM, Håkan Liljegren via use-livecode wrote:
>> When my students turn in their assignments all their individual stacks 
>> usually have the same name. If I try to loop through all of them there seems 
>> to be no way to close one stack and move on to the next one (with the same 
>> name) without getting the dialog asking if I want to save, purge or cancel 
>> the previous stack?!
>> 
>> I have tried to:
>> 
>> close stack tStack
>> delete stack tStack
>> 
>> That didn't work
>> 
>> I then thought that it might be that the IDE needed some more time to clean 
>> up so I added a loop:
>> delete stack tStack
>> repeat while tStack is among the lines of the openStacks
>>wait for 100 milliseconds with messages
>> end repeat
>> 
>> That didn’t work either as the next time I try to open a stack with the same 
>> name I get the dialog again
>> 
>> I then thought that maybe the handler needs to be finished before the 
>> cleanup is done so I tried to rewrite using a system where I added all files 
>> that should be crawled into a local variable and added the current stack 
>> into another and created a system using the send command:
>> 
>> local sFileList  # A text with one file path per line for all 
>> files that should be crawled
>> local sCurrentStack# The name of the currently crawled stack
>> 
>> on stackCrawl
>>if sCurrentStack is among the lines of the openstacks then
>>   send “stackCrawl” to me in 500 milliseconds
>>else if sCurrentStack is not empty then
>>   # Now we now that the sCurrentStack is not among the open stacks (I.e 
>> closed and deleted)
>>   put empty into sCurrentStack
>>   if sFileList is empty then
>>  # All stacks crawled => We are finished!
>>   else
>>  send “stackCrawl” to me in 0 milliseconds
>>   end if
>>else # sCurrentStack is empty so we should move on to the next stack in 
>> the file list!
>>   put line 1 of sFileList into tFile
>>   delete line 1 of sFileList
>>   put the openStacks into tStackList
>>   open stack tFile
>>   repeat for each line aStack in the openStacks
>>  if aStack is not among the lines of tStackList then
>> put aStack into sCurrentStack
>> exit repeat
>>  end if
>>   end repeat
>>   # Do needed operations on sCurrentStack
>>   delete sCurrentStack
>>  send “stackCrawl” to me in 500 milliseconds
>>end if
>> end stackCrawl
>>  This also gives the same result. Then I realised that the stacks I have 
>> also have sub stacks so I also tried:
>> 
>>   put the substacks of stack sCurrentStack into tSubStacks
>>   lock messages
>>   repeat for each line tSubStack in tSubstacks
>>  close stack tSubStack
>>   end repeat
>>   delete stack sCurrentStack
>>   unlock messages
>> 
>> I even found a call to revIDEHandleObjectDeleted by peeking into the IDE 
>> itself. Added a call to that function but still no luck!
>> 
>> Even if I loop through all my stacks (by clicking purge for each stack) and 
>> then do a "put the openStacks” I can see that the last stack is not among 
>> the the open stacks. But, if I now try to open the first stack in the list 
>> again I still get a dialog asking me about what I want to do with the last 
>> stack in the list (save, purge or cancel)!
>> 
>> So as soon as a stack I opened via script there is no way to close it via 
>> script and also remove it from the internal workings of the IDE. Is there 
>> ANY way to really delete the stack from the IDE memory so I can open a stack 
>> with the same name without a dialog popping up?!
>> 
>> I’ve reported this as a bug 
>> 

Re: How to loop through stacks with same name?

2023-04-04 Thread Craig Newman via use-livecode
Bi.

There has been much discussion on the forum why, if the “destroyStack” property 
is set to “true”, there still seems to be remnants of that stack that linger 
when the “close stack” command is given.

Nonetheless, have you established that this property is set? If not, set it, 
and let us know if that worked.

Craig

> On Apr 4, 2023, at 11:18 AM, Paul Dupuis via use-livecode 
>  wrote:
> 
> I believe there is a IDE handler you can call to unload a stack - something 
> like "revUnloadStack" or similar, but I do not recall the exact API name.
> 
> Hopefully, some one else on the list has the exact API details. 
> Alternatively, contact supp...@livecode.com and ask what the IDE API is to 
> unload a stack.
> 
> 
> 
> On 4/4/2023 10:22 AM, Håkan Liljegren via use-livecode wrote:
>> When my students turn in their assignments all their individual stacks 
>> usually have the same name. If I try to loop through all of them there seems 
>> to be no way to close one stack and move on to the next one (with the same 
>> name) without getting the dialog asking if I want to save, purge or cancel 
>> the previous stack?!
>> 
>> I have tried to:
>> 
>> close stack tStack
>> delete stack tStack
>> 
>> That didn't work
>> 
>> I then thought that it might be that the IDE needed some more time to clean 
>> up so I added a loop:
>> delete stack tStack
>> repeat while tStack is among the lines of the openStacks
>>wait for 100 milliseconds with messages
>> end repeat
>> 
>> That didn’t work either as the next time I try to open a stack with the same 
>> name I get the dialog again
>> 
>> I then thought that maybe the handler needs to be finished before the 
>> cleanup is done so I tried to rewrite using a system where I added all files 
>> that should be crawled into a local variable and added the current stack 
>> into another and created a system using the send command:
>> 
>> local sFileList  # A text with one file path per line for all 
>> files that should be crawled
>> local sCurrentStack# The name of the currently crawled stack
>> 
>> on stackCrawl
>>if sCurrentStack is among the lines of the openstacks then
>>   send “stackCrawl” to me in 500 milliseconds
>>else if sCurrentStack is not empty then
>>   # Now we now that the sCurrentStack is not among the open stacks (I.e 
>> closed and deleted)
>>   put empty into sCurrentStack
>>   if sFileList is empty then
>>  # All stacks crawled => We are finished!
>>   else
>>  send “stackCrawl” to me in 0 milliseconds
>>   end if
>>else # sCurrentStack is empty so we should move on to the next stack in 
>> the file list!
>>   put line 1 of sFileList into tFile
>>   delete line 1 of sFileList
>>   put the openStacks into tStackList
>>   open stack tFile
>>   repeat for each line aStack in the openStacks
>>  if aStack is not among the lines of tStackList then
>> put aStack into sCurrentStack
>> exit repeat
>>  end if
>>   end repeat
>>   # Do needed operations on sCurrentStack
>>   delete sCurrentStack
>>  send “stackCrawl” to me in 500 milliseconds
>>end if
>> end stackCrawl
>>  This also gives the same result. Then I realised that the stacks I have 
>> also have sub stacks so I also tried:
>> 
>>   put the substacks of stack sCurrentStack into tSubStacks
>>   lock messages
>>   repeat for each line tSubStack in tSubstacks
>>  close stack tSubStack
>>   end repeat
>>   delete stack sCurrentStack
>>   unlock messages
>> 
>> I even found a call to revIDEHandleObjectDeleted by peeking into the IDE 
>> itself. Added a call to that function but still no luck!
>> 
>> Even if I loop through all my stacks (by clicking purge for each stack) and 
>> then do a "put the openStacks” I can see that the last stack is not among 
>> the the open stacks. But, if I now try to open the first stack in the list 
>> again I still get a dialog asking me about what I want to do with the last 
>> stack in the list (save, purge or cancel)!
>> 
>> So as soon as a stack I opened via script there is no way to close it via 
>> script and also remove it from the internal workings of the IDE. Is there 
>> ANY way to really delete the stack from the IDE memory so I can open a stack 
>> with the same name without a dialog popping up?!
>> 
>> I’ve reported this as a bug 
>> (https://quality.livecode.com/show_bug.cgi?id=24163), but is still 
>> interested if anyone has at least a workaround…
>> 
>> ___
>> use-livecode mailing list
>> use-livecode@lists.runrev.com
>> Please visit this url to subscribe, unsubscribe and manage your subscription 
>> preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
> 
> 
> ___
> use-livecode mailing list
> use-livecode@lists.runrev.com
> Please visit this url to subscribe, unsubscribe and 

test

2023-04-04 Thread Bob Sneidar via use-livecode
This is a test of the use list. 

Bob S

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: How to loop through stacks with same name?

2023-04-04 Thread Paul Dupuis via use-livecode
I believe there is a IDE handler you can call to unload a stack - 
something like "revUnloadStack" or similar, but I do not recall the 
exact API name.


Hopefully, some one else on the list has the exact API details. 
Alternatively, contact supp...@livecode.com and ask what the IDE API is 
to unload a stack.




On 4/4/2023 10:22 AM, Håkan Liljegren via use-livecode wrote:

When my students turn in their assignments all their individual stacks usually 
have the same name. If I try to loop through all of them there seems to be no 
way to close one stack and move on to the next one (with the same name) without 
getting the dialog asking if I want to save, purge or cancel the previous 
stack?!

I have tried to:

close stack tStack
delete stack tStack

That didn't work

I then thought that it might be that the IDE needed some more time to clean up 
so I added a loop:
delete stack tStack
repeat while tStack is among the lines of the openStacks
wait for 100 milliseconds with messages
end repeat

That didn’t work either as the next time I try to open a stack with the same 
name I get the dialog again

I then thought that maybe the handler needs to be finished before the cleanup 
is done so I tried to rewrite using a system where I added all files that 
should be crawled into a local variable and added the current stack into 
another and created a system using the send command:

local sFileList  # A text with one file path per line for all files 
that should be crawled
local sCurrentStack# The name of the currently crawled stack

on stackCrawl
if sCurrentStack is among the lines of the openstacks then
   send “stackCrawl” to me in 500 milliseconds
else if sCurrentStack is not empty then
   # Now we now that the sCurrentStack is not among the open stacks (I.e 
closed and deleted)
   put empty into sCurrentStack
   if sFileList is empty then
  # All stacks crawled => We are finished!
   else
  send “stackCrawl” to me in 0 milliseconds
   end if
else # sCurrentStack is empty so we should move on to the next stack in the 
file list!
   put line 1 of sFileList into tFile
   delete line 1 of sFileList
   put the openStacks into tStackList
   open stack tFile
   repeat for each line aStack in the openStacks
  if aStack is not among the lines of tStackList then
 put aStack into sCurrentStack
 exit repeat
  end if
   end repeat
   # Do needed operations on sCurrentStack
   delete sCurrentStack
  send “stackCrawl” to me in 500 milliseconds
end if
end stackCrawl
  
This also gives the same result. Then I realised that the stacks I have also have sub stacks so I also tried:


   put the substacks of stack sCurrentStack into tSubStacks
   lock messages
   repeat for each line tSubStack in tSubstacks
  close stack tSubStack
   end repeat
   delete stack sCurrentStack
   unlock messages

I even found a call to revIDEHandleObjectDeleted by peeking into the IDE 
itself. Added a call to that function but still no luck!

Even if I loop through all my stacks (by clicking purge for each stack) and then do 
a "put the openStacks” I can see that the last stack is not among the the open 
stacks. But, if I now try to open the first stack in the list again I still get a 
dialog asking me about what I want to do with the last stack in the list (save, 
purge or cancel)!

So as soon as a stack I opened via script there is no way to close it via 
script and also remove it from the internal workings of the IDE. Is there ANY 
way to really delete the stack from the IDE memory so I can open a stack with 
the same name without a dialog popping up?!

I’ve reported this as a bug 
(https://quality.livecode.com/show_bug.cgi?id=24163), but is still interested 
if anyone has at least a workaround…

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode



___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


How to loop through stacks with same name?

2023-04-04 Thread Håkan Liljegren via use-livecode
When my students turn in their assignments all their individual stacks usually 
have the same name. If I try to loop through all of them there seems to be no 
way to close one stack and move on to the next one (with the same name) without 
getting the dialog asking if I want to save, purge or cancel the previous 
stack?!

I have tried to:

close stack tStack
delete stack tStack

That didn't work

I then thought that it might be that the IDE needed some more time to clean up 
so I added a loop:
delete stack tStack
repeat while tStack is among the lines of the openStacks
   wait for 100 milliseconds with messages
end repeat

That didn’t work either as the next time I try to open a stack with the same 
name I get the dialog again

I then thought that maybe the handler needs to be finished before the cleanup 
is done so I tried to rewrite using a system where I added all files that 
should be crawled into a local variable and added the current stack into 
another and created a system using the send command:

local sFileList  # A text with one file path per line for all files 
that should be crawled 
local sCurrentStack# The name of the currently crawled stack

on stackCrawl
   if sCurrentStack is among the lines of the openstacks then
  send “stackCrawl” to me in 500 milliseconds
   else if sCurrentStack is not empty then
  # Now we now that the sCurrentStack is not among the open stacks (I.e 
closed and deleted)
  put empty into sCurrentStack
  if sFileList is empty then
 # All stacks crawled => We are finished!
  else
 send “stackCrawl” to me in 0 milliseconds
  end if
   else # sCurrentStack is empty so we should move on to the next stack in the 
file list!
  put line 1 of sFileList into tFile
  delete line 1 of sFileList
  put the openStacks into tStackList
  open stack tFile
  repeat for each line aStack in the openStacks
 if aStack is not among the lines of tStackList then
put aStack into sCurrentStack
exit repeat
 end if
  end repeat
  # Do needed operations on sCurrentStack
  delete sCurrentStack
 send “stackCrawl” to me in 500 milliseconds
   end if
end stackCrawl
 
This also gives the same result. Then I realised that the stacks I have also 
have sub stacks so I also tried:

  put the substacks of stack sCurrentStack into tSubStacks
  lock messages
  repeat for each line tSubStack in tSubstacks
 close stack tSubStack
  end repeat
  delete stack sCurrentStack
  unlock messages

I even found a call to revIDEHandleObjectDeleted by peeking into the IDE 
itself. Added a call to that function but still no luck!

Even if I loop through all my stacks (by clicking purge for each stack) and 
then do a "put the openStacks” I can see that the last stack is not among the 
the open stacks. But, if I now try to open the first stack in the list again I 
still get a dialog asking me about what I want to do with the last stack in the 
list (save, purge or cancel)!

So as soon as a stack I opened via script there is no way to close it via 
script and also remove it from the internal workings of the IDE. Is there ANY 
way to really delete the stack from the IDE memory so I can open a stack with 
the same name without a dialog popping up?!

I’ve reported this as a bug 
(https://quality.livecode.com/show_bug.cgi?id=24163), but is still interested 
if anyone has at least a workaround…

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode