Posted 04 August 2016 - 04:40 AM
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 doesnot credit you a code line if it is a comment, so no cheating!
Cyclomatic Complexity
Spoiler
The complexity calculator used within CodeMetrics is based on the Cyclomatic Complexityalgorithm, in which the complexity increases based on the number of subroutines.
For example, the following code has a complexity of 1 as there are no subroutines:
print("Hello Sailor!")
sleep(1)
print("Goodbye.")
The following code would have a complexity of 3 as there is one subroutine:
name = io.read()
if (name == "Sailor") then
print("Hello!")
end
As the depth level increases, the complexity increases at a quicker rate. Therefore, nestingstatements and using anonymous functions is discouraged as this accelerates the complexity.
Spoiler
Apologies for the bad thread formatting, this is my first post :)/>Edited on 04 August 2016 - 12:58 PM