Jump to content




CodeMetrics - Calculate code properties and complexity

api computer lua

3 replies to this topic

#1 mgthomas99

  • Members
  • 4 posts
  • LocationUK

Posted 04 August 2016 - 03:40 AM

Posted Image

Welcome to CodeMetrics!
CodeMetrics is a lightweight API used to calculate Lua script properties such as code line count and complexity.

Installation
pastebin get qq1X1kWw CodeMetrics

How to use CodeMetrics
Command Line
To use CodeMetrics from the command line, simply execute
CodeMetrics ["path_to_script"]
Doing so will print basic script information about "path_to_script" to the shell,

From Another Script
To use CodeMetrics from another script, we must first load the CodeMetrics API.
os.loadAPI("path/to/CodeMetrics")
To retrieve the code properties of a Lua script, you must first create a Script 'object'.
my_script = CodeMetrics.new("path/to/myscript")
There! Now we are ready to obtain information about the file "myscript"!

Here are the current functions we can execute on the object:
	my_script:get_character_count()
	my_script:get_subroutine_count()
	my_script:get_cyclo_complexity()
	my_script:get_function_count()
	my_script:get_count("if")	-- This can be any keyword
	my_script:get_line_count()
CodeMetrics also takes into account comments and quotes and does
not credit you a code line if it is a comment, so no cheating!

Cyclomatic Complexity
Spoiler

Spoiler

Edited by GeorgeEpicGen, 04 August 2016 - 01:58 PM.


#2 Emma

  • Members
  • 216 posts
  • Locationtmpim

Posted 04 August 2016 - 04:21 AM

Neat, although using the word coroutines the way you are can be a little confusing for Lua as there are specific 'coroutine' objects that are different from what you are counting. Maybe 'subroutine' makes more sense? Cool idea though, and very nicely implemented as well.

#3 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 04 August 2016 - 05:17 AM

I believe "block" is the term you're after. I'm not sure that block depth really matters to performance, though, unless you're defining functions within functions or somesuch.

#4 mgthomas99

  • Members
  • 4 posts
  • LocationUK

Posted 04 August 2016 - 01:57 PM

View PostIncinirate, on 04 August 2016 - 04:21 AM, said:

Neat, although using the word coroutines the way you are can be a little confusing for Lua as there are specific 'coroutine' objects that are different from what you are counting. Maybe 'subroutine' makes more sense? Cool idea though, and very nicely implemented as well.
You're absoultely right, I have edited CodeMetrics and renamed the 'script#get_coroutine_count' to 'script#get_subroutine_count'. The PasteBin link has also changed.

View PostBomb Bloke, on 04 August 2016 - 05:17 AM, said:

I believe "block" is the term you're after. I'm not sure that block depth really matters to performance, though, unless you're defining functions within functions or somesuch.
No, block depth does not matter to performance, but that is not what the calculator... calculates. The calculator gets complexity, not performance.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users