Jump to content
Wikipedia The Free Encyclopedia

Module:SimpleDebug/doc

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Jmarchn (talk | contribs) at 13:57, 20 October 2019 (Created page with ''''Contains a functions to help debug the lua modules.''' ==Uses== {| class="wikitable" |- ! colspan="3" | One or several point to watch |- | colspan="3" |'''Va...'). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision .Revision as of 13:57, 20 October 2019 by Jmarchn (talk | contribs) (Created page with ''''Contains a functions to help debug the lua modules.''' ==Uses== {| class="wikitable" |- ! colspan="3" | One or several point to watch |- | colspan="3" |'''Va...')
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
icon This is a documentation subpage for Module:SimpleDebug.
It may contain usage information, categories and other content that is not part of the original module page.

Contains a functions to help debug the lua modules.

Uses

One or several point to watch
Variables
Name Default
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
function var (avar, where)
  • avar: a variable: string, number, boolean or table.
  • where: is optional.
array (anarray, where)
  • anarray: a table of variables => {var1, var2...}
  • where: is optional.
namearray (anarray, where)
  • anarray: a table of pairs of name-variable => {name1, var1, name2, var2...}.
  • where: is optional.
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 ()

Only ads a break line in s.

wheretos (where)

where: a explained point to watch stored in s.

arraytos (anarray, where)

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

namearraytos (anarray, where)

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

Examples

One point to watch

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

returns:

0.33


localsd=require"Module:SimpleDebug"
locala={{1,2,3},{4,5,6},{7,8,9}}
returnsd.var(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.var(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.var(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.var(a))

displays:

Lua error:Module:YourModule:Line:{ { 1, 2, 3, } , { 4, 5, 6, } , { 7, 8, 9, } , }


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

returns:

12 - "Hello"


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

returns:

a: 12 - b: "Hello"

Several points to watch

localsd=require"Module:SimpleDebug"
a=12
b='Hello'
sd.arraytos({a,b},1)
a=a+a
b=b..' world!'
sd.arraytos({'a',a,'b',b},'Finally')
returnsd.s

returns:

1 => 12 - "Hello"

Finally => 24 - "Hello world!"


localsd=require"Module:SimpleDebug"
sd.breakline()
a=12
b='Hello'
c=false
sd.namearraytos({'a',a,'b',b,'c',c},1)
a=a+a
b=b..' world!'
sd.namearraytos({'a',a,'b',b},'Finally')
error(sd.s)

returns:

Lua error:Module:YourModule:Line:

1 => a: 12 - b: "Hello" - c: false

Finally => a: 24 - b: "Hello world!"


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.arraytos({string.len(a),a},i)
end

returns:

Lua error:Module:YourModule:Line:

3 => 8 - "AAAAAAAA"

4 => 10 - "AAAAAAAAAA"

5 => 12 - "AAAAAAAAAAAA".


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