Jump to content
Wikipedia The Free Encyclopedia

Module:SimpleDebug/doc: Difference between revisions

From Wikipedia, the free encyclopedia

Jmarchn (talk | contribs)

1 user groups
extendedconfirmed
3,495 edits
|
undo
Content deleted Content added
Line 250: Line 250:
a = a + a
a = a + a
b = b..' world!'
b = b..' world!'
sd.vtos ('Finally',(削除) ' (削除ここまで)a(削除) ',a,'b' (削除ここまで),b)
sd.vtos ('Finally',a,b)
return sd.s
return sd.s
</syntaxhighlight>
</syntaxhighlight>
Line 278: Line 278:
{{color|red|'''1 {{=}}> a: 12 • b: "Hello" • c: false'''}}
{{color|red|'''1 {{=}}> a: 12 • b: "Hello" • c: false'''}}


{{color|red|'''Finally {{=}}> a: 24 • b: "Hello world!"'''}}(削除) (削除ここまで)
{{color|red|'''Finally {{=}}> a: 24 • b: "Hello world!"'''}}



==== Variables and their presentation with conditions ====
==== Variables and their presentation with conditions ====

Revision as of 17:16, 23 October 2019

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).

Uses

One or several points to watch
Function abbreviations: w: where. n: names. v: variables. s: string.
Variables
Name Default
tab.oneline true

If true, it shows the table in a line; Alternatively with a line for each element of the table and with an indent for each nested table.

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.

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.

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

One point to watch

Following the flow

localsd=require"Module:SimpleDebug"
returnsd.v('Here is reached')

returns:

Here is reached


Number of decimal places and value of a variable

localsd=require"Module:SimpleDebug"
sd.dec=2
returnsd.v(1/3)

returns:

0.33


The value of several variables

localsd=require"Module:SimpleDebug"
locala=12
localb='Hello'
returnsd.v(a,b)

returns:

12 • "Hello"


Non-assigned variable detection

localsd=require"Module:SimpleDebug"
locala=true
returnsd.v(a,b)

returns:

true • nil


The value of a table

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

returns:

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


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

returns:

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


localsd=require"Module:SimpleDebug"
SD.allidx=true
locala={{1,2,3},{4,5,6},{7,8,9}}
returnsd.v(a)

returns:

{ [1]={ [1]=1, [2]=2, [3]=3, } , [2]={ [1]=4, [2]=5, [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, 2, 3, } , { 4, 5, 6, } , { 7, 8, 9, } , }


The value of a table in multiline

localsd=require"Module:SimpleDebug"
SD.tab.oneline=false
locala={{First=1,2,3},'Middle',{4,Second=5,6}}
returnsd.v(a)

retorna:

table#1 {
 table#2 {
 2,
 3,
 ["First"] = 1,
 },
 "Middle",
 table#3 {
 4,
 6,
 ["Second"] = 5,
 },
} 


The value of several variables with their name in a point

localsd=require"Module:SimpleDebug"
locala=12
localb='Hello'
returnsd.nv('a',a,'b',b)

returns:

a: 12 • b: "Hello"


Several points to watch

Following the flow

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:

Error de Lua:Mòdul:VostreMòdul:Línia: little number

big=12

little number.


Monitoring of several variables

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

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 によって変換されたページ (->オリジナル) /