Counting Lines of Code

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
gshearne
Posts: 36
Joined: Mon Jun 02, 2014 4:41 am

Counting Lines of Code

Post by gshearne » Thu Sep 05, 2019 1:50 pm

Hi,
Is there any quick/easy way to count the lines of code in a stack. I have several stacks with lots of cards and just want a simple count of the lines.
Thanks
Greg

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Counting Lines of Code

Post by Klaus » Thu Sep 05, 2019 1:53 pm

Hi Greg,

Code: Select all

...
put the num of lines of the script of stack "your stack here" into NumberOfStackScriptLines
...
Gather all infos in a repeat loop over the cards in your stack and that's it.


Best

Klaus

AndyP
Posts: 634
Joined: Wed Aug 27, 2008 12:57 pm
Contact:

Re: Counting Lines of Code

Post by AndyP » Thu Sep 05, 2019 8:19 pm

This stack maybe our interest to you.

http://livecodeshare.runrev.com/stack/5 ... eporter-LC
Andy .... LC CLASSIC ROCKS!

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: Counting Lines of Code

Post by dunbarx » Fri Sep 06, 2019 2:54 pm

Hi,

I did this for a large project once. I counted the total number of lines and then deducted all lines that either were empty or began with "--".

You will need to examine each card and accumulate the scripts of all the controls on each. Then add the stack script. You can do all that without actually navigating to each card right?

Craig

trevix
Posts: 1064
Joined: Sat Feb 24, 2007 11:25 pm
Contact:

Re: Counting Lines of Code

Post by trevix » Tue May 28, 2024 2:24 pm

Hello.
I tried the script reporter opening my quite large stack, but the Script Reporter freezes just after listing all the cards and stacks.
I using LC10dp8
Trevix
OSX 14.6.1 xCode 15 LC 10 RC1 iOS 15> Android 7>

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: Counting Lines of Code

Post by dunbarx » Tue May 28, 2024 2:29 pm

I use this to track a large project:

Code: Select all

on countLines
   lock screen
   set the cursor to busy
   lock messages
   
   repeat with y = 1 to the number of cds  --ACCESS CURRENT STACK
      put y && the number of controls of cd y into line y of  tCon
      put the script of cd y & return after accum
      repeat with u = 1 to the number of controls of cd y
         put the script of control u of cd y & return after accum
      end repeat
   end repeat
   put the script of this stack after accum
   
   put the substacks of this stack into stackList --ACCESS ALL SUBSTACKS
   
   repeat with v= 1 to the number of lines of stackList 
      go stack line v of stacklist
      if the result <> "" then
      end if
      repeat with y = 1 to the number of cds 
         put the script of cd y & return after accum
         repeat with u = 1 to the number of controls of cd y
            put the script of control u of cd y & return after accum
         end repeat
      end repeat
      put return & the script of this stack after accum
   end repeat
   
   repeat for each line tline in accum
      if char 1 to 2 of tLine <> "--" and tLine <> "" then add 1 to numLines --COUNT ONLY "WORKING" LINES
      add 1 to totLines
   end repeat
   
   repeat with v= 1 to the number of lines of stackList --CLOSE SUBSTACKS
      close stack line v of stacklist
   end repeat
   
   answer "# active Lines:" && numLines & return & "Total Lines:" && totLines
end countLines
Craig

Post Reply