Jump to content
Wikipedia The Free Encyclopedia

Module:SimpleDebug/doc: Difference between revisions

From Wikipedia, the free encyclopedia

Gonnym (talk | contribs)

3 user groups
autoreviewer, extendedconfirmed, templateeditor
263,382 edits
|
undo
Content deleted Content added
(9 intermediate revisions by 4 users not shown)
Line 16: Line 16:
| <code>tab.oneline</code> || true||
| <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 ''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.(削除) (削除ここまで)|-
* If it is ''true'' and it does not contain nested tables, it shows the table in a line.
|-

| <code>tab.allidx</code> || false ||
| <code>tab.allidx</code> || false ||
If it is true then also displays the numerical indexes of a table.
If it is true then also displays the numerical indexes of a table.
Line 70: Line 73:
| <code>maxlines.doerror</code> || true ||
| <code>maxlines.doerror</code> || true ||
If it is true and <code>maxlines.num</code> is reached, <code>error(s)</code> is called.
If it is true and <code>maxlines.num</code> is reached, <code>error(s)</code> is called.
|-
|<code>counter</code> || false ||
Adds an autoincremental number at the beginning of each call of a function.
|-
|-
| colspan="3" |'''Functions'''
| colspan="3" |'''Functions'''
Line 201: Line 207:
<syntaxhighlight lang="Lua">
<syntaxhighlight lang="Lua">
local SD = require "Module:SimpleDebug"
local SD = require "Module:SimpleDebug"
SD.allidx = true
SD(追記) .tab (追記ここまで).allidx = true
local a = {{1,2,3},{4,(削除) 5 (削除ここまで),6},{7,8,9}}
local a = {{1,2,3},{4,(追記) nil (追記ここまで),6},{7,8,9}}
return SD.v (a)
return SD.v (a)
</syntaxhighlight>
</syntaxhighlight>
Line 209: Line 215:
{
{
[1]={[1]=1, [2]=2, [3]=3, },
[1]={[1]=1, [2]=2, [3]=3, },
[2]={[1]=4(削除) , [2]=5 (削除ここまで), [3]=6, },
[2]={[1]=4, [3]=6, },
[3]={[1]=7, [2]=8, [3]=9, },
[3]={[1]=7, [2]=8, [3]=9, },
}
}
Line 222: Line 228:
displays:
displays:


{{color|red|'''Lua error:Module:''YourModule'':''Line'':{}}
{{color|red|'''Lua error:Module:''YourModule'':''Line'':{(追記) ''' (追記ここまで)}}
<div style="color:red; font-family:monospace, monospace"><b>
<font color="red"><b>
(削除) (削除ここまで)[1] = {1, 2, 3, },
(追記) &nbsp; (追記ここまで) (追記) &nbsp; (追記ここまで)[1] = {1, 2, 3, },(追記) <br> (追記ここまで)
(削除) (削除ここまで)[2] = {4, 5, 6, },
(追記) &nbsp; (追記ここまで) (追記) &nbsp; (追記ここまで)[2] = {4, 5, 6, },(追記) <br> (追記ここまで)
(削除) (削除ここまで)[3] = {7, 8, 9, },
(追記) &nbsp; (追記ここまで) (追記) &nbsp; (追記ここまで)[3] = {7, 8, 9, },(追記) <br> (追記ここまで)
&nbsp;}
(削除) } (削除ここまで)</b></(削除) font (削除ここまで)>
</b></(追記) div (追記ここまで)>




Line 292: Line 299:
returns:
returns:


{{color|red|'''Error(削除) de Lua (削除ここまで):(削除) Mòdul (削除ここまで):''(削除) VostreMòdul (削除ここまで)'':''(削除) Línia (削除ここまで)'':(削除) little number (削除ここまで)'''}}
{{color|red|'''(追記) Lua (追記ここまで)Error:(追記) Module (追記ここまで):''(追記) Your module (追記ここまで)'':''(追記) Line (追記ここまで)'':'''}}

{{color|red|'''little number'''}}


{{color|red|'''big{{=}}12'''}}
{{color|red|'''big{{=}}12'''}}
Line 299: Line 308:




====With counter====
<syntaxhighlight lang="lua">
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
</syntaxhighlight>
returns:

1 • 2

2 • 4

3 • 6
==== Monitoring of several variables ====
==== Monitoring of several variables ====

<syntaxhighlight lang="Lua">
<syntaxhighlight lang="Lua">
local SD = require "Module:SimpleDebug"
local SD = require "Module:SimpleDebug"
Line 362: Line 393:
{{color|red|'''5 {{=}}> 12 • "AAAAAAAAAAAA".'''}}
{{color|red|'''5 {{=}}> 12 • "AAAAAAAAAAAA".'''}}


<includeonly>
<includeonly>(追記) {{Sandbox other|| (追記ここまで)
<!-- Categories below this line; interwikis at Wikidata -->
[[Category:Modules for test tools]]
[[Category:Modules for test tools]]
</includeonly>
(追記) }} (追記ここまで)</includeonly>

Latest revision as of 13:29, 17 October 2021

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

[edit ]
One or several points to watch
Function abbreviations: w: where. n: names. v: variables. s: string.
Variables
Name Default
tab.oneline 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.
tab.allidx false

If it is true then also displays the numerical indexes of a table.

dec -1

Spaces for the decimals:

  • -1: It displays all required decimals.
  • 0: No decimals.
  • n: 1: one decimal, 2: two decimals, etc.
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)
  • where: point label.
v (...)
  • ...: a number of variables = var1, var2...
wv (where, ...)
  • where: point label.
  • ...: a number of variables = var1, var2...
nv (...)
  • ...: a number of pairs of name-variable = name1, var1, name2, var2....
wnv (where, ...)
  • where: point label.
  • ...: a number of pairs of name-variable = name1, var1, name2, var2....
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 maxlines.num is reached, error(s) is called.

counter false

Adds an autoincremental number at the beginning of each call of a function.

Functions
breakline ()

Adds a break line in s.

wtos (where)

Equal to w, but the return string is stored in s.

vtos (...)

Equal to v, but the return string is stored in s.

wvtos (where, ...)

Equal to wv, but the return string is stored in s.

nvtos (...)

Equal to nv, but the return string is stored in s.

wnvtos (where, ...)

Igual a wnv, but the return string is stored in s.

Examples

[edit ]

One point to watch

[edit ]

Following the flow

[edit ]
localSD=require"Module:SimpleDebug"
returnSD.v('Here is reached')

returns:

Here is reached


Number of decimal places and value of a variable

[edit ]
localSD=require"Module:SimpleDebug"
SD.dec=2
returnSD.v(1/3)

returns:

0.33


Nohtml

[edit ]
localSD=require"Module:SimpleDebug"
SD.nohtml=true
returnSD.v("<b>bold</b>")

returns:

"⪡b⪢bold⪡/b⪢"


Plaintext

[edit ]
localSD=require"Module:SimpleDebug"
SD.plaintext=true
returnSD.v("<b>bold</b>")

returns:

"bold"


The value of several variables

[edit ]
localSD=require"Module:SimpleDebug"
locala=12
localb='Hello'
returnSD.v(a,b)

returns:

12 • "Hello"


Non-assigned variable detection

[edit ]
localSD=require"Module:SimpleDebug"
locala=true
returnSD.v(a,b)

returns:

true • nil


The value of a table

[edit ]
localSD=require"Module:SimpleDebug"
locala={1,tab='a','b'}
returnSD.v(a)

returns: { 1, "b", [tab]="a", }


localSD=require"Module:SimpleDebug"
locala={{1,2,3},{4,5,6},{7,8,9}}
returnSD.v(a)

returns:

{
 [1] = {1, 2, 3, },
 [2] = {4, 5, 6, },
 [3] = {7, 8, 9, },
} 


localSD=require"Module:SimpleDebug"
locala={{First=1,2,3},{4,Second=5,6},{7,8,9}}
returnSD.v(a)

returns:

{ 
 [1] = {2, 3, [First]=1, },
 [2] = {4, 6, [Second]=5, },
 [3] = {7, 8, 9, },
}


localSD=require"Module:SimpleDebug"
SD.tab.allidx=true
locala={{1,2,3},{4,nil,6},{7,8,9}}
returnSD.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:

localSD=require"Module:SimpleDebug"
locala={{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

[edit ]
localSD=require"Module:SimpleDebug"
SD.tab.oneline=false
locala={{First=1,2,3},'Middle',{4,Second=5,6}}
returnSD.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

[edit ]
localSD=require"Module:SimpleDebug"
locala=12
localb='Hello'
returnSD.nv('a',a,'b',b)

returns:

a: 12 • b: "Hello"


Several points to watch

[edit ]

Following the flow

[edit ]
localSD=require"Module:SimpleDebug"
localtab={1,12,7}
functionp.CheckValues()
localfunctionLittleNum()
SD.wtos('little number')
end
localfunctionBigNum(num)
SD.wtos('big='..num)
end
fori,numinipairs(tab)do
ifnum>9then
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

[edit ]
localSD=require"Module:SimpleDebug"
functionIncrem()
localn=0
fori=1,3do
n=n+2
SD.vtos(n)
end
end
SD.counter=true
Increm()
returnSD.s

returns:

1 • 2

2 • 4

3 • 6

Monitoring of several variables

[edit ]
localSD=require"Module:SimpleDebug"
a=12
b='Hello'
SD.vtos(1,a,b)
a=a+a
b=b..' world!'
SD.vtos('Finally',a,b)
returnSD.s

returns:

1 => 12 • "Hello"

Finally => 24 • "Hello world!"


localSD=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

[edit ]
localSD=require"Module:SimpleDebug"
SD.breakline()
SD.enabled=false
SD.maxlines.num=3
locala='AA'
fori=1,10do
a=a+'AA'
ifi==3then
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".


AltStyle によって変換されたページ (->オリジナル) /