File: debug.lua

package info (click to toggle)
naev 0.8.2-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 386,084 kB
  • sloc: ansic: 93,149; xml: 87,292; python: 2,347; sh: 904; makefile: 654; lisp: 162; awk: 4
file content (71 lines) | stat: -rw-r--r-- 2,274 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
-- =======================================================================================
--
-- Debug facility
-- 
-- Include this script to output debug messages
--
-- 
-- =======================================================================================


-- =======================================================================================
--
-- Script-global variables
-- 
-- =======================================================================================
--
dbg = {}
-- 
-- =======================================================================================


-- =======================================================================================
--
-- Print function
--
-- Usage :
--    dbg.stdOutput( strPrefixParam, numIndentParam, strMessageParam, boolDebugParam )
-- 
-- =======================================================================================
--
function dbg.stdOutput(strPrefixParam, numIndentParam, strMessageParam, boolDebugParam)
	-- Local variables with default values
	local strPrefix  = ""
	local numIndent  = 0
	local strMessage = ""
	local boolDebug = true

	-- Check parameters
	if type(strPrefixParam)=="string" then
		strPrefix  = strPrefixParam
	end
	if type(numIndentParam)=="number" then
		numIndent  = numIndentParam
	end
	if type(strMessageParam)=="string" then
		strMessage = strMessageParam
	end
	if type(boolDebugParam)=="boolean" then
		boolDebug = boolDebugParam
	end

	-- Built indentation and line feed strings
	local strIndent = ""
	local strLF = ""
	if numIndent>=0 then
		strIndent = string.rep("    ", numIndent)
	end
	if numIndent<0 then
		strLF = "\n"
	end

	-- Print message
	if boolDebug then
		local tabDateTime = os.date("*t")
		local strDate = string.format( "%02i", tabDateTime.day ) .. "/" .. string.format( "%02i", tabDateTime.month ) .. "/" .. string.format( "%04i", tabDateTime.year )
		local strTime = string.format( "%02i", tabDateTime.hour ) .. "." .. string.format( "%02i", tabDateTime.min ) .. "." .. string.format( "%02i", tabDateTime.sec )
		print ( string.format( "%s(%s:%s) (%s) : %s : %s%s", strLF, strDate, strTime, time.str(), strPrefix, strIndent, strMessage ) )
	end
end
-- 
-- =======================================================================================