Module:SimpleDebug/doc: Difference between revisions
Mabega sura (talk | contribs) No edit summary Tags: Mobile edit Mobile web edit Advanced mobile edit |
|||
Line 3: | Line 3: | ||
It is designed so that its functions are called from within the module that is to be debugged, calls that will have to be part of the code (of the module that you have designed, or that you want to improve or adapt) until you decide to delete them (when you already have determined the bug). Thus, you do not have to call any of its functions from an invoke. |
It is designed so that its functions are called from within the module that is to be debugged, calls that will have to be part of the code (of the module that you have designed, or that you want to improve or adapt) until you decide to delete them (when you already have determined the bug). Thus, you do not have to call any of its functions from an invoke. |
||
==Uses== |
|||
Uses class wikitable colspan 3 One or several points to watch colspan 3 Function abbreviations code w code where. code n code names. V code variables code> string Variables |
|||
{| class="wikitable" |
|||
Name Default |
|||
|- |
|||
code tab oneline code true |
|||
! colspan="3" | One or several points to watch |
|||
If it is or it is true and contains nested tables, it will show a line for each item in the table and with an indent for each nested table |
|||
|- |
|||
If it is true and it does not contain nested tables it shows the table in a line. |
|||
| colspan="3" | Function abbreviations: <code>w</code>: where. <code>n</code>: names. <code>v</code>: variables. <code>s</code>: string. |
|||
|- |
|||
| colspan="3" |'''Variables''' |
|||
|- |
|||
| '''Name'''||'''Default'''|| |
|||
|- |
|||
| <code>tab.oneline</code> || true|| |
|||
* If it is ''false'' or it is ''true'' and contains nested tables, it will show a line for each item in the table and with an indent for each nested table. |
|||
* If it is ''true'' and it does not contain nested tables, it shows the table in a line. |
|||
|- |
|- |
||
Line 90: | Line 99: | ||
==Examples== |
==Examples== |
||
One point to watch Following the flow |
===One point to watch === |
||
==== Following the flow ==== |
|||
syntaxhighlight lang |
<syntaxhighlight lang="Lua"> |
||
local SD require Module |
local SD = require "Module:SimpleDebug" |
||
return SD.v Here is reached |
return SD.v ('Here is reached') |
||
syntaxhighlight |
</syntaxhighlight> |
||
returns |
returns: |
||
Here is reached Number of decimal places and value of a variable |
|||
Here is reached |
|||
syntaxhighlight lang Lua |
|||
local SD require Module SimpleDebug" |
|||
SD.dec 2 |
|||
==== Number of decimal places and value of a variable ==== |
|||
return SD.v 1/3 syntaxhighlight |
|||
<syntaxhighlight lang="Lua"> |
|||
return No html |
|||
local SD = require "Module:SimpleDebug" |
|||
syntaxhighlight lang Lua |
|||
SD.dec = 2 |
|||
local SD require Module Simple Debug |
|||
return SD.v (1/3) |
|||
SD no html true |
|||
</syntaxhighlight> |
|||
return SD v bbold b |
|||
returns: |
|||
syntaxhighlight |
|||
return Plaintext lang Lua local SD require Module Simple Debug |
|||
0.33 |
|||
SD.plaintext true |
|||
return SDv bold b |
|||
syntaxhighlight |
|||
==== Nohtml ==== |
|||
return The value of several variables syntaxhighlight lang Lua |
|||
<syntaxhighlight lang="Lua"> |
|||
local SD require Module SimpleDebug" |
|||
local |
local SD = require "Module:SimpleDebug" |
||
SD.nohtml = true |
|||
local b Hello |
|||
return SD |
return SD.v ("<b>bold</b>") |
||
</syntaxhighlight> |
|||
return 12 Hello |
|||
returns: |
|||
Non-assigned variable detection syntaxhighlight lang Lua local SD require Module Simple Debug |
|||
local a true |
|||
"⪡b⪢bold⪡/b⪢" |
|||
return SD v a b |
|||
syntaxhighlight |
|||
returns true The value of a tablesyntaxhighlight lang Lua |
|||
==== Plaintext ==== |
|||
local SD require Module Simple Debug |
|||
<syntaxhighlight lang="Lua"> |
|||
local a 1 tab a b |
|||
local SD = require "Module:SimpleDebug" |
|||
return SD v a |
|||
SD.plaintext = true |
|||
syntax highlight returns 1 b tab a |
|||
return SD.v ("<b>bold</b>") |
|||
syntaxhighlight lang Lua |
|||
</syntaxhighlight> |
|||
local SD require Module SimpleDebug |
|||
returns: |
|||
local a 1 2 3 4 5 6 7 8 9 return SD v syntaxhighlight |
|||
returns 1 2 3 2 4 5 6 |
|||
"bold" |
|||
3 7 8 9 syntaxhighlight lang Lua |
|||
local SD require Module SimpleDebug" |
|||
local a First 1 2 3 4 Second 5 6 7 8 9 |
|||
==== The value of several variables ==== |
|||
<syntaxhighlight lang="Lua"> |
|||
local SD = require "Module:SimpleDebug" |
|||
local a = 12 |
|||
local b = 'Hello' |
|||
return SD.v (a,b) |
|||
</syntaxhighlight> |
|||
returns: |
|||
12 • "Hello" |
|||
==== Non-assigned variable detection ==== |
|||
<syntaxhighlight lang="Lua"> |
|||
local SD = require "Module:SimpleDebug" |
|||
local a = true |
|||
return SD.v (a,b) |
|||
</syntaxhighlight> |
|||
returns: |
|||
true • nil |
|||
====The value of a table==== |
|||
<syntaxhighlight lang="Lua"> |
|||
local SD = require "Module:SimpleDebug" |
|||
local a = {1, tab='a', 'b'} |
|||
return SD.v (a) |
return SD.v (a) |
||
syntaxhighlight |
</syntaxhighlight> |
||
returns 1 2 3 First 1 |
|||
returns: |
|||
2 4 6 Second 5 3 7 8 9 |
|||
{ 1, "b", [tab]="a", } |
|||
syntaxhighlight lang Lua |
|||
local SD require Module SimpleDebug |
|||
SD.tab allidx true |
|||
<syntaxhighlight lang="Lua"> |
|||
local a 1 2 3 4 6 7 8 9 |
|||
local SD = require "Module:SimpleDebug" |
|||
return SD v a |
|||
local a = {{1,2,3},{4,5,6},{7,8,9}} |
|||
Ssyntaxhighligh 1 2 2 3 2 1 4 3 6 3 1 7 2 8 3 9 |
|||
return SD.v (a) |
|||
Usually you implement these functions with error function |
|||
syntaxhighlight |
</syntaxhighlight> |
||
returns: |
|||
local SD require Modul Simple Debug |
|||
local a 1 2 3 4 5 6 7 8 9 |
|||
{ |
|||
error SD v a |
|||
[1] = {1, 2, 3, }, |
|||
syntaxhighlight |
|||
[2] = {4, 5, 6, }, |
|||
displays color red Lua errorModule Your Module Line |
|||
[3] = {7, 8, 9, }, |
|||
div style color red;font family monospace monospace b |
|||
} |
|||
  1 1 2 3 b |
|||
  2 4 5 6 br |
|||
    3 78 9 br |
|||
<syntaxhighlight lang="Lua"> |
|||
nbsp |
|||
local SD = require "Module:SimpleDebug" |
|||
b div All values of a table in multiline |
|||
local a = {{First=1,2,3},{4,Second=5,6},{7,8,9}} |
|||
<syntaxhighlight lang Lua |
|||
return SD.v (a) |
|||
</syntaxhighlight> |
|||
returns: |
|||
{ |
|||
[1] = {2, 3, [First]=1, }, |
|||
[2] = {4, 6, [Second]=5, }, |
|||
[3] = {7, 8, 9, }, |
|||
} |
|||
<syntaxhighlight lang="Lua"> |
|||
local SD = require "Module:SimpleDebug" |
|||
SD.tab.allidx = true |
|||
local a = {{1,2,3},{4,nil,6},{7,8,9}} |
|||
return SD.v (a) |
|||
</syntaxhighlight> |
|||
returns: |
|||
{ |
|||
[1]={[1]=1, [2]=2, [3]=3, }, |
|||
[2]={[1]=4, [3]=6, }, |
|||
[3]={[1]=7, [2]=8, [3]=9, }, |
|||
} |
|||
Usually, you implement these functions with error function: |
|||
<syntaxhighlight lang="Lua"> |
|||
local SD = require "Module:SimpleDebug" |
|||
local a = {{1,2,3},{4,5,6},{7,8,9}} |
|||
error (SD.v (a)) |
|||
</syntaxhighlight> |
|||
displays: |
|||
{{color|red|'''Lua error:Module:''YourModule'':''Line'':{'''}} |
|||
<div style="color:red; font-family:monospace, monospace"><b> |
|||
[1] = {1, 2, 3, },<br> |
|||
[2] = {4, 5, 6, },<br> |
|||
[3] = {7, 8, 9, },<br> |
|||
} |
|||
</b></div> |
|||
==== All values of a table in multiline ==== |
|||
<syntaxhighlight lang="Lua"> |
|||
local SD = require "Module:SimpleDebug" |
local SD = require "Module:SimpleDebug" |
||
SD.tab.oneline = false |
SD.tab.oneline = false |
||
local |
local a = {{First=1,2,3},'Middle',{4,Second=5,6}} |
||
return |
return SD.v (a) |
||
syntaxhighlight |
</syntaxhighlight> |
||
retorna |
retorna: |
||
pre1 2 2 3 |
|||
<pre> |
|||
First 1 2 Middle 3 1 4 |
|||
{ |
|||
26 |
|||
[1] = { |
|||
Second 5 |
|||
[1] = 2, |
|||
pre |
|||
[2] = 3, |
|||
The value of several variables with their name in a point |
|||
["First"] = 1, |
|||
syntaxhighlight lang Lua |
|||
}, |
|||
local SD require ModuleSimpleDebug |
|||
[2] = "Middle", |
|||
local a 12 |
|||
[3] = { |
|||
local b Hello |
|||
[1] = 4, |
|||
return SDnv a b syntaxhighlight> |
|||
[2] = 6, |
|||
returns |
|||
["Second"] = 5, |
|||
}, |
|||
} |
|||
</pre> |
|||
==== The value of several variables with their name in a point ==== |
|||
<syntaxhighlight lang="Lua"> |
|||
local SD = require "Module:SimpleDebug" |
|||
local a = 12 |
|||
local b = 'Hello' |
|||
return SD.nv ('a',a,'b',b) |
|||
</syntaxhighlight> |
|||
returns: |
|||
a: 12 • b: "Hello" |
|||
a 12 b Hello |
|||
===Several points to watch=== |
===Several points to watch=== |
Revision as of 11:40, 17 August 2020
Contains a functions to help debug the lua modules. It allows to collect and view the values of several variables and/or points in your lua program, from a module (which is usual) or in several modules (which are required from the main module).
It is designed so that its functions are called from within the module that is to be debugged, calls that will have to be part of the code (of the module that you have designed, or that you want to improve or adapt) until you decide to delete them (when you already have determined the bug). Thus, you do not have to call any of its functions from an invoke.
Uses
One or several points to watch | ||
---|---|---|
Function abbreviations: w : where. n : names. v : variables. s : string.
| ||
Variables | ||
Name | Default | |
tab.oneline |
true |
|
tab.allidx |
false |
If it is true then also displays the numerical indexes of a table. |
dec |
-1 |
Spaces for the decimals:
|
enabled |
true |
If it is false all calls to the below functions do nothing. |
nohtml |
false |
In strings, it replaces < for ⪡ and > for ⪢. |
plaintext |
false |
Deletes html format. |
One point to watch | ||
Functions | ||
w (where) |
| |
v (...) |
| |
wv (where, ...) |
| |
nv (...) |
| |
wnv (where, ...) |
| |
Several points to watch | ||
Variables | ||
Name | Default | |
s |
The string variable that holds the returned values from the next functions. | |
maxlines.num |
100 |
The maxim number of lines (on calling the next functions). |
maxlines.doerror |
true |
If it is true and |
counter |
false |
Adds an autoincremental number at the beginning of each call of a function. |
Functions | ||
breakline () |
Adds a break line in | |
wtos (where) |
Equal to | |
vtos (...) |
Equal to | |
wvtos (where, ...) |
Equal to | |
nvtos (...) |
Equal to | |
wnvtos (where, ...) |
Igual a |
Examples
One point to watch
Following the flow
local SD = require "Module:SimpleDebug"
return SD.v ('Here is reached')
returns:
Here is reached
Number of decimal places and value of a variable
local SD = require "Module:SimpleDebug"
SD.dec = 2
return SD.v (1/3)
returns:
0.33
Nohtml
local SD = require "Module:SimpleDebug"
SD.nohtml = true
return SD.v ("<b>bold</b>")
returns:
"⪡b⪢bold⪡/b⪢"
Plaintext
local SD = require "Module:SimpleDebug"
SD.plaintext = true
return SD.v ("<b>bold</b>")
returns:
"bold"
The value of several variables
local SD = require "Module:SimpleDebug"
local a = 12
local b = 'Hello'
return SD.v (a,b)
returns:
12 • "Hello"
Non-assigned variable detection
local SD = require "Module:SimpleDebug"
local a = true
return SD.v (a,b)
returns:
true • nil
The value of a table
local SD = require "Module:SimpleDebug"
local a = {1, tab='a', 'b'}
return SD.v (a)
returns: { 1, "b", [tab]="a", }
local SD = require "Module:SimpleDebug"
local a = {{1,2,3},{4,5,6},{7,8,9}}
return SD.v (a)
returns:
{ [1] = {1, 2, 3, }, [2] = {4, 5, 6, }, [3] = {7, 8, 9, }, }
local SD = require "Module:SimpleDebug"
local a = {{First=1,2,3},{4,Second=5,6},{7,8,9}}
return SD.v (a)
returns:
{ [1] = {2, 3, [First]=1, }, [2] = {4, 6, [Second]=5, }, [3] = {7, 8, 9, }, }
local SD = require "Module:SimpleDebug"
SD.tab.allidx = true
local a = {{1,2,3},{4,nil,6},{7,8,9}}
return SD.v (a)
returns:
{ [1]={[1]=1, [2]=2, [3]=3, }, [2]={[1]=4, [3]=6, }, [3]={[1]=7, [2]=8, [3]=9, }, }
Usually, you implement these functions with error function:
local SD = require "Module:SimpleDebug"
local a = {{1,2,3},{4,5,6},{7,8,9}}
error (SD.v (a))
displays:
Lua error:Module:YourModule:Line:{
[1] = {1, 2, 3, },
[2] = {4, 5, 6, },
[3] = {7, 8, 9, },
}
All values of a table in multiline
local SD = require "Module:SimpleDebug"
SD.tab.oneline = false
local a = {{First=1,2,3},'Middle',{4,Second=5,6}}
return SD.v (a)
retorna:
{ [1] = { [1] = 2, [2] = 3, ["First"] = 1, }, [2] = "Middle", [3] = { [1] = 4, [2] = 6, ["Second"] = 5, }, }
The value of several variables with their name in a point
local SD = require "Module:SimpleDebug"
local a = 12
local b = 'Hello'
return SD.nv ('a',a,'b',b)
returns:
a: 12 • b: "Hello"
Several points to watch
Following the flow
local SD = require "Module:SimpleDebug"
local tab = {1,12,7}
function p.CheckValues ()
local function LittleNum()
SD.wtos ('little number')
end
local function BigNum(num)
SD.wtos ('big='..num)
end
for i, num in ipairs(tab) do
if num > 9 then
BigNum(num)
else
LittleNum()
end
end
error (SD.s)
end
returns:
Lua Error:Module:Your module:Line:
little number
big=12
little number.
With counter
local SD = require "Module:SimpleDebug"
function Increm()
local n = 0
for i = 1, 3 do
n = n + 2
SD.vtos (n)
end
end
SD.counter = true
Increm()
return SD.s
returns:
1 • 2
2 • 4
3 • 6
Monitoring of several variables
local SD = require "Module:SimpleDebug"
a = 12
b = 'Hello'
SD.vtos (1,a,b)
a = a + a
b = b..' world!'
SD.vtos ('Finally',a,b)
return SD.s
returns:
1 => 12 • "Hello"
Finally => 24 • "Hello world!"
local SD = require "Module:SimpleDebug"
SD.breakline ()
a = 12
b = 'Hello'
c = false
SD.nvtos (1,'a',a,'b',b,'c',c)
a = a + a
b = b..' world!'
SD.nvtos ('Finally','a',a,'b',b)
error (SD.s)
displays:
Lua error:Module:YourModule:Line:
1 => a: 12 • b: "Hello" • c: false
Finally => a: 24 • b: "Hello world!"
Variables and their presentation with conditions
local SD = require "Module:SimpleDebug"
SD.breakline()
SD.enabled = false
SD.maxlines.num = 3
local a = 'AA'
for i = 1, 10 do
a = a + 'AA'
if i == 3 then
SD.enabled = true
end
SD.nvtos (i, string.len(a), a)
end
displays:
Lua error:Module:YourModule:Line:
3 => 8 • "AAAAAAAA"
4 => 10 • "AAAAAAAAAA"
5 => 12 • "AAAAAAAAAAAA".