PUT . . .

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9388
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

PUT . . .

Post by richmond62 » Fri Jun 03, 2022 7:52 pm

At the risk of being a pain-in-the-donkey (surely not), I will reiterate this here, as I buried
it in an off-topic post where it is far less likely to get noticed.

The default of this sort:

Code: Select all

on mouseUp
put "Happy Christmas"
end mouseUp
is that 'Happy Christmas' ends up in the messageBox, which is NOT always convenient, and I wonder if:

pseudo:

put XXX into messageBox


or, perhaps:

put XXX into msgBox

might not be better, so there is NO default.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9842
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: PUT . . .

Post by FourthWorld » Fri Jun 03, 2022 8:41 pm

richmond62 wrote:
Fri Jun 03, 2022 7:52 pm
At the risk of being a pain-in-the-donkey (surely not), I will reiterate this here, as I buried
it in an off-topic post where it is far less likely to get noticed.

The default of this sort:

Code: Select all

on mouseUp
put "Happy Christmas"
end mouseUp
is that 'Happy Christmas' ends up in the messageBox, which is NOT always convenient, and I wonder if:

pseudo:

put XXX into messageBox


or, perhaps:

put XXX into msgBox

might not be better, so there is NO default.
A good idea, but too late, by about 33 years: unspecified puts going to the Message Box was established by HyperCard 1.0 back in '87, faithfully followed by every xTalk since. I see little hope of that changing now.

FWIW I tend to use a custom "PutS" handler (short for "Put String"), which lets me route and re-route however I need.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9388
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: PUT . . .

Post by richmond62 » Fri Jun 03, 2022 8:43 pm

FWIW
Worth a lot more than perhaps you realise. 8)

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9388
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: PUT . . .

Post by richmond62 » Fri Jun 03, 2022 8:48 pm

A good idea, but too late, by about 33 years: unspecified puts going to the Message Box was established by HyperCard 1.0 back in '87, faithfully followed by every xTalk since.
Considering unfaithfulness elsewhere I wonder why that feature has to stay etched in stone.
-
upgrade.jpeg
-
And, as we all know, what was right-on in 1989 might not be the best thing in 2022 . . .

Of course, if you don't agree, I'll dig out my Macintosh LC 475 from the attic in my house in
Scotland (it runs Mac OS 7.1) and ship it to you forth-with . . . err, when I'm there in August.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9842
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: PUT . . .

Post by FourthWorld » Fri Jun 03, 2022 9:08 pm

richmond62 wrote:
Fri Jun 03, 2022 8:48 pm
A good idea, but too late, by about 33 years: unspecified puts going to the Message Box was established by HyperCard 1.0 back in '87, faithfully followed by every xTalk since.
Considering unfaithfulness elsewhere I wonder why that feature has to stay etched in stone.
SuperCard, Plus, and later Gain and MetaCard might have been quick to follow suit if only for its design purpose: it's a simple way to get feedback during development while a script is running. Remember, the first version of HC had no debugger.

With MetaCard and Gain, which both ran on Unix, it served a similar second purpose: unspecified "put" output goes to stdout, useful for providing feedback in command-line tools.

The only downside is that it's really easy to put in a diagnostic "put" statement, and then forget to take it out before shipping. For things like that I have a habit of ending the line with "--!" as a flag I can search for the clean out diagnostic stuff when it comes time to finally build.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9670
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: PUT . . .

Post by dunbarx » Fri Jun 03, 2022 9:37 pm

I have a habit of ending the line with "--!" as a flag I can search for the clean out diagnostic stuff...
We all have stuff like that. There are support groups for people like you and me.

Craig

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9388
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: PUT . . .

Post by richmond62 » Fri Jun 03, 2022 9:42 pm

There are support groups for people like you and me.
Quite possibly, but I, for one, am quite happy inside my head. 8)

mtalluto
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 125
Joined: Tue Apr 11, 2006 7:02 pm
Location: Seattle, WA
Contact:

Re: PUT . . .

Post by mtalluto » Sat Jun 04, 2022 12:32 am

We made some handy code that will find orphaned puts in our LiveCode projects. I'll post it here in its entirety. It references some UI that is part of a bigger Developer Tool we use in-house. You can focus on the relevant handlers and change the field reference to something else. You could also just dump the results into a variable and out-put it to the message box (hahaha).

You can use regex or filter. I do not remember why I stayed with the filter option. Both options are there for you to use.

Code: Select all

//>GLOBALS
global gSavedStackRect, gSoftwarePasskeys


on mouseUp
     local tHeight, tMainStackList, tSavedStackHeight, tSavedTop

     //DOCUMENTATION
     //THIS CODE WILL FIND ORPHANED PUTS THROUGHOUT YOUR PROGRAM
     //YOUR CODE WILL NOT BE TOUCHED IN YOUR PROGRAM

     //INPUT: NO INPUT
     //ACTION: CLICK 'GLOBAL PUT' BUTTON
     //OUTPUT: A DROP DOWN WINDOW WILL APPEAR UNDER THE TOOLS
     //A LIST OF LINES THAT WERE FOUND WILL BE GENERATED
     //CLICK ANY OF THE LINES TO BE TAKEN TO YOUR ORPHANED PUT LINE

     lock screen
     put empty into fld "clean put" of this stack
     set vis of fld "clean put" of this stack to not(vis of fld "clean put" of this stack)

     --HIDE PUT RESULTS
     if not(vis of fld "clean put" of this stack) then
          if gSavedStackRect is empty then put "0,42,1021,97" into gSavedStackRect
          set the rect of stack "dev tools" to gSavedStackRect
          delete variable gSavedStackRect
          exit to top
     end if

     put the mainstacks into tMainStackList
     put lf & the stacksInUse after tMainStackList

     filter tMainStackList without "rev*"
     filter tMainStackList without "Message Box"
     filter tMainStackList without "DEV TOOLS"
     filter tMainStackList without "com.livecode*"
     filter tMainStackList without "ws.*"
     filter tMainStackList without "tsNet*"
     filter tMainStackList without "home"
     filter tMainStackList without "answer dialog"
     filter tMainStackList without "ask dialog"

     csFindErrantPuts tMainStackList

     --STORE STANDARD SIZE VALUES
     put the rect of stack "dev tools" into gSavedStackRect
     put the height of stack "dev tools" into tSavedStackHeight
     put the top of stack "dev tools" into tSavedTop

     --SIZE DEV TOOLS TO SHOW ALL RESULTS
     put the formattedHeight of fld "clean put" into tHeight
     put min(tHeight,700) into tHeight
     set the height of stack "dev tools" to (tHeight + (tSavedStackHeight * 2))
     set the top of stack "dev tools" to tSavedTop

     --SIZE CLEAN PUT FIELD TO SHOW ALL RESULTS
     set the width of fld "clean put" to the width of stack "dev tools"
     set the left of fld "clean put" to 0
     set the height of fld "clean put" to (tSavedStackHeight + tHeight)
     set the top of fld "clean put" to tSavedStackHeight
     unlock screen
end mouseUp


on csFindErrantPuts pMainStacks
     local tSubstackList

     repeat for each line xMainStack in pMainStacks
          --GENERATE LIST OF SUBSTACKS TO MAINSTACK
          put the substacks of stack xMainStack into tSubstackList

          --CHECK MAINSTACK SCRIPT
          checkMainstackScript xMainStack

          --CHECK CARD SCRIPT OF MAINSTACK
          checkCardScript xMainStack

          repeat for each line xSubstack in tSubstackList
               --CHECK STACK SCRIPT
               checkSubstackScript xSubstack, xMainStack

               --CHECK THE CARDS
               checkCardScript xSubstack, xMainStack
          end repeat
     end repeat
end csFindErrantPuts


command checkMainstackScript pStack
     local tScript, tStackLongID

     put the long id of stack pStack into tStackLongID
     put getScript(tStackLongID) into tScript
     if tScript is not empty then cleanScript tScript, pStack
end checkMainstackScript


command checkSubstackScript pParentStack, pMainstack
     local tScript, tStackLongID

     put the long id of stack pParentStack into tStackLongID
     put getScript(tStackLongID) into tScript
     if tScript is not empty then cleanScript tScript, pParentStack
end checkSubstackScript


on checkCardScript pParentStack, pMainstack
     local tCardCount, tCardList, tScript

     if pMainstack is not empty then
          --CHECKING A SUBSTACK
          put num of cards of stack pParentStack of stack pMainstack into tCardCount

          --BUILD A LIST OF THE CARD LONG IDS
          repeat with xCard = 1 to tCardCount
               put the long id of card xCard of stack pParentStack of stack pMainstack & lf after tCardList
          end repeat
     else
          --CHECKING A MAINSTACK
          put num of cards of stack pParentStack into tCardCount

          --BUILD A LIST OF THE CARD LONG IDS
          repeat with xCard = 1 to tCardCount
               put the long id of card xCard of stack pParentStack & lf after tCardList
          end repeat
     end if

     repeat for each line xCardLongID in tCardList
          --GET CARD SCRIPT
          put getScript(xCardLongID) into tScript

          --CLEAN CARD SCRIPT
          if tScript is not empty then cleanScript tScript, ,xCardLongID

          --CHECK CONTROLS FOR THE CARD
          checkControlScript xCardLongID, pParentStack, pMainstack
     end repeat
end checkCardScript


on checkControlScript pCard, pStack
     local tCardName, tControlCount, tControlCounter, tControlID
     local tControlLongID, tControlName, tScript

     put num of controls in pCard into tControlCount
     put 0 into tControlCounter
     repeat tControlCount
          add 1 to tControlCounter

          put the script of control tControlCounter of pCard into tScript

          if tScript is not empty then
               put the id of control tControlCounter of pCard into tControlID
               put the long id of control tControlCounter of pCard into tControlLongID
               put the short name of pCard into tCardName
               put the name of control tControlCounter of card tCardName of stack pStack into tControlName
               cleanScript tScript, pStack, tCardName, tControlLongID --WE WILL WANT TO ADD CARD DETAILS TO OUTPUT
          end if

     end repeat
end checkControlScript


function getScript pLongID, pItem
     local tScript

     if pItem is empty then put 1 into pItem

     --ATTEMPT TO GET THE SCRIPT
     try
          put the script of pLongID into tScript

     catch tError
          try
               set the passkey of pLongID to item pItem of gSoftwarePasskeys
               put the script of pLongID into tScript
          catch tError
               add 1 to pItem
               get getScript (pLongID,pItem)
          end try
     end try

     put empty into pItem
     return tScript
end getScript


command cleanScript pScript, pStack, pCard, pControlLongID
     local tCompressedScriptA, tFoundLine, tFoundWord, tNoCommentedCode
     local tNumOfDuplicates, tScriptMaster, tSkipLines, tTempLine
     local tWordToFind

     put pScript into tScriptMaster

     --BUILD EXPRESSION
     --put "^\s*put\s+\" & quote into tExpression

     --FILTER CODE
     --filter pScript with regex pattern tExpression
     filter lines of pScript with "* put *"
     filter lines of pScript without "*into*"
     filter lines of pScript without "*after*"
     filter lines of pScript without "*before*"
     filter lines of pScript without "*\"

     --REMOVE COMMENTED OUT CODE
     repeat for each line xLine in pScript
          put xLine into tTempLine
          replace " " with empty in tTempLine

          if char 1 to 2 of tTempLine = "//" or char 1 to 2 of tTempLine = "--" or char 1 to 2 of tTempLine = "##" then
               --DO NOTHING
          else
               --REMOVE LINE FROM pScript
               put xLine & lf after tNoCommentedCode
          end if
     end repeat

     --PUT NO COMMENTED CODE BACK INTO pScript
     put tNoCommentedCode into pScript

     --PLACE DUPLICATES NEXT TO EACH OTHER THIS THIS LIST
     sort lines of pScript

     --COUNT DUPLICATE TERMS
     repeat for each line xLine in pScript
          add 1 to tCompressedScriptA[xLine]
     end repeat

     --WE MAY HAVE DUPLICATE TERMS TO SEARCH FOR
     --THUS, WE MUST DESIGN THE REPEAT TO SEARCH FOR DUPLICATE TERMS ALL THE WAY THROUGH THE CODE BEFORE MOVING TO THE NEXT SEARCH TERM
     set wholeMatches to true
     repeat for each key xTerm in tCompressedScriptA
          put tCompressedScriptA[xTerm] into tNumOfDuplicates
          put 0 into tSkipLines

          repeat with xCurrentLine = 1 to tNumOfDuplicates
               --FIND TERM
               put lineOffset(xTerm,tScriptMaster,tSkipLines) into tFoundLine
               if tFoundLine > 0 then put tSkipLines + tFoundline into tFoundline else next repeat

               --CLEAN LEADING SPACES IN CODE
               //NOTE TO SELF. DO NOT ATTEMPT TO REMOVE SPACES WHEN CREATING tCompressedScriptA
               //BECAUSE IT WILL THROW OFF THE lineOffset SEARCH ABOVE AND CAUSE THE LINE NOT TO BE FOUND
               put word 1 of xTerm into tWordToFind
               put Offset(tWordToFind,xTerm) into tFoundWord
               delete char 1 to (tFoundWord - 1) of xTerm

               --GENERATE OUTPUT
               switch
                    case pControlLongID is not empty
                         --CONTROL
                         put "line" && tFoundLine && "of CONTROL:" && pControlLongID && "CARD:" && pCard && "STACK:" && \
                               pStack & lf & "   " & xTerm & lf after fld "clean put" of this stack
                         set the textColor of the last line of fld "clean put" to 140,140,140
                         exit switch
                         break

                    case pCard is not empty
                         --CARD
                         put "line" && tFoundLine && "of" && "CARD:" && pCard && "STACK:" && pStack & lf & "   " & xTerm & lf \
                               after fld "clean put" of this stack
                         set the textColor of the last line of fld "clean put" to 140,140,140
                         exit switch
                         break

                    default
                         put "line" && tFoundLine && "of" && "STACK:" && pStack & lf & "   " & xTerm & lf after fld "clean put" of this stack
                         set the textColor of the last line of fld "clean put" to 140,140,140
                         break
               end switch

               put tFoundLine into tSkipLines
          end repeat
     end repeat
end cleanScript
Mark Talluto
--
Canela
design - develop - deploy: https://appli.io
Database and Cloud for LiveCode Developers: https://livecloud.io
Company: https://canelasoftware.com

Post Reply

Return to “Talking LiveCode”