Open main menu
Home
Random
Donate
Recent changes
Special pages
Community portal
Preferences
About Stockhub
Disclaimers
Search
User menu
Talk
Contributions
Create account
Log in
Editing
Module:SimpleDebug/doc
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Examples== ===One point to watch === ==== Following the flow ==== <syntaxhighlight lang="Lua"> local SD = require "Module:SimpleDebug" return SD.v ('Here is reached') </syntaxhighlight> returns: Here is reached ==== Number of decimal places and value of a variable ==== <syntaxhighlight lang="Lua"> local SD = require "Module:SimpleDebug" SD.dec = 2 return SD.v (1/3) </syntaxhighlight> returns: 0.33 ==== Nohtml ==== <syntaxhighlight lang="Lua"> local SD = require "Module:SimpleDebug" SD.nohtml = true return SD.v ("<b>bold</b>") </syntaxhighlight> returns: "βͺ‘bβͺ’boldβͺ‘/bβͺ’" ==== Plaintext ==== <syntaxhighlight lang="Lua"> local SD = require "Module:SimpleDebug" SD.plaintext = true return SD.v ("<b>bold</b>") </syntaxhighlight> returns: "bold" ==== 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) </syntaxhighlight> returns: { 1, "b", [tab]="a", } <syntaxhighlight lang="Lua"> local SD = require "Module:SimpleDebug" local a = {{1,2,3},{4,5,6},{7,8,9}} return SD.v (a) </syntaxhighlight> returns: { [1] = {1, 2, 3, }, [2] = {4, 5, 6, }, [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}} 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" SD.tab.oneline = false local a = {{First=1,2,3},'Middle',{4,Second=5,6}} return SD.v (a) </syntaxhighlight> retorna: <pre> { [1] = { [1] = 2, [2] = 3, ["First"] = 1, }, [2] = "Middle", [3] = { [1] = 4, [2] = 6, ["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" ===Several points to watch=== ==== Following the flow ==== <syntaxhighlight lang="lua"> 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 </syntaxhighlight> returns: {{color|red|'''Lua Error:Module:''Your module'':''Line'':'''}} {{color|red|'''little number'''}} {{color|red|'''big{{=}}12'''}} {{color|red|'''little number.'''}} ====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 ==== <syntaxhighlight lang="Lua"> 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 </syntaxhighlight> returns: 1 => 12 ββ’β "Hello" Finally => 24 ββ’β "Hello world!" <syntaxhighlight lang="Lua"> 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) </syntaxhighlight> displays: {{color|red|'''Lua error:Module:''YourModule'':''Line'':'''}} {{color|red|'''1 {{=}}> a: 12 ββ’β b: "Hello" ββ’β c: false'''}} {{color|red|'''Finally {{=}}> a: 24 ββ’β b: "Hello world!"'''}} ==== Variables and their presentation with conditions ==== <syntaxhighlight lang="Lua"> 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 </syntaxhighlight> displays: {{color|red|'''Lua error:Module:''YourModule'':''Line'':'''}} {{color|red|'''3 {{=}}> 8 ββ’β "AAAAAAAA"'''}} {{color|red|'''4 {{=}}> 10 ββ’β "AAAAAAAAAA"'''}} {{color|red|'''5 {{=}}> 12 ββ’β "AAAAAAAAAAAA".'''}} <includeonly>{{Sandbox other|| <!-- Categories below this line; interwikis at Wikidata --> [[Category:Modules for test tools]] }}</includeonly>
Summary:
Please note that all contributions to Stockhub may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Stockhub:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)