1 -- console & printing related functions
7 ------------------------------------------------------------------------------------------------------------
8 -- alias for 'debugInfo'
12 ------------------------------------------------------------------------------------------------------------
13 -- Build color tag for use with debugInfo
14 function colorTag(r
, g
, b
, a
)
15 local function compToLetter(comp
)
19 comp
= math
.floor(clamp(comp
, 0, 255) / 16) + 1
20 --debugInfo("Comp = " .. tostring(comp))
21 return ComponentToLetter
[comp
]
23 return "@{" .. compToLetter(r
) .. compToLetter(g
) .. compToLetter(b
) .. compToLetter(a
) .. "}"
26 -------------------------------------------------------------------------------------------------
27 -- Display a string, splitting it when too long
28 function dumpSplittedString(str
)
30 local numParts
= math
.floor(string.len(str
) / splitSize
) + 1
31 for i
= 0, numParts
do
32 debugInfo(string.sub(str
, i
* splitSize
, i
* splitSize
+ splitSize
- 1))
36 -------------------------------------------------------------------------------------------------
37 -- display debug info with warning color
38 function debugWarning(msg
)
39 debugInfo(warningTag
.. msg
)
42 -------------------------------------------------------------------------------------------------
43 -- dump content of a lua object
44 function luaObject(obj
, maxDepth
)
51 runCommand("luaObject", "__tmpInstance", select(maxDepth
, maxDepth
, 10))
56 -------------------------------------------------------------------------------------------------
57 -- dump content of a lua object (other version)
58 -- output : object with a "write" function that display the result. if nil, 'output' default to the global 'io'
60 function writeTable(t
, output
)
61 if output
== nil then output
= io
end
62 function writeSpace(n
)
68 function writeTableR(t
, n
)
69 if (type(t
) == "table")
73 for key
, value
in pairs(t
) do
74 if ( type(value
) == "table")
79 writeTableR(value
, n
+1)
81 elseif (type(value
) == "string")
83 value
= "\"" ..value
.. "\""
85 output
.write(key
, "=", value
,", \n")
86 elseif (type(value
) == "number")
89 output
.write(key
, "=", value
,", \n")
101 --function loadTable(fileName)
103 -- local file = io.open(fileName, "r")
105 -- function loadTableR(file)
108 -- while (line=file:read("*l")) ~= "}" then
110 -- if line == "{" then
118 -- if file:read("*l") ~= "{" then
119 -- debugInfo("file doesn't store a valid table")
123 -- local resultT = loadTableR(file)
134 ComponentToLetter
= { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }
135 warningTag
= colorTag(255, 127, 0)
142 -- for vianney's tests : if debugInfo function wasn't registered externally, then use the standard 'print' instead
143 if debugInfo
== nil then
146 function print(a0
, a1
, a2
, a3
, a4
, a5
)
148 if a0
~= nil then result
= result
.. tostring(a0
) end
149 if a1
~= nil then result
= result
.. " " ..tostring(a1
) end
150 if a2
~= nil then result
= result
.. " " ..tostring(a2
) end
151 if a3
~= nil then result
= result
.. " " ..tostring(a3
) end
152 if a4
~= nil then result
= result
.. " " ..tostring(a4
) end
153 if a5
~= nil then result
= result
.. " " ..tostring(a5
) end
154 if result
~= nil then debugInfo(result
) end
159 function gotoFile(name
, line
)
160 local path
= fileLookup(name
)
162 local luaEditorPath
= os
.getenv("R2ED_LUA_EDITOR_PATH")
163 if luaEditorPath
== nil then
164 debugInfo([[ Can't launch editor to edit lua file, please set ]] ..
165 [[ the environment variable R2ED_LUA_EDITOR_PATH ]] ..
166 [[ with the path of your editor. ]])
169 launchProgram(luaEditorPath
, path
.. "/" .. tostring(line
))