Editing
OtherX:Lua
(section)
Jump to navigation
Jump to search
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!
===Use the debug console=== The debug console lets you test code while you're working on it. This saves you a lot of time. It also lets you avoid saving unecessary revisions just to see if your code is working. Instead you'll only be saving known working code after you're done with adding a feature. Don't wait too long though, in case your power or internet goes out. You can test expressions such as: <pre>= 2+2</pre> which will return <pre>4</pre> as you'd expect. You can also call into any function that is ''visible'' from outside. If you defined this function as part of for instance table p which you're then returning to Scribunto, you can call into this function from the debug console: <syntaxhighlight lang='lua'> local p = {} function p.calculate(num) return num + 2 end return p </syntaxhighlight> <pre>= p.calculate(3)</pre> or <pre>mw.log( p.calculate(3) )</pre> yields <pre>5</pre> If this function were instead returning a table you could inspect it like so: <syntaxhighlight lang='lua'> local p = {} function p.calculate2(num) return { num + 1, num + 2} end return p </syntaxhighlight> <pre>mw.logObject( p.calculate2(3) )</pre> Sometimes you might not be interested in the output and only want to check if a function works. In the above example you could have used one of the following for that: <pre>= #p.calculate2(3)</pre> <pre>= type(p.calculate2(3))</pre> Of course calling any Lua function from the outside, expects the function to only take one argument, the frame object, which we can't provide in the debug console, so we have to work around that. This is usually done by providing two entry-point functions, one which takes the frame object, grabs the arguments from it an passes it on to the ''real'' function like so: <syntaxhighlight lang='lua'> local p = {} function p.calculate(frame) local args = frame:getParent().args return p._calculate(args) end function p._calculate(args) local num = args[1] return num + 2 end return p </syntaxhighlight> Normal invocation of the module will use the p.calculate() function, but now you can debug the output from the real p._calculate() function in the debug console like so: <pre>= p._calculate({3})</pre>
Summary:
Please note that all contributions to OtherX 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
OtherX:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Create account
Log in
Namespaces
Project page
Discussion
English
Views
Read
Edit source
View history
More
Purge cache
Search
Discord
Discord
Navigation
Main page
About us
Random page
Otherside
Legends of the Mara
Otherside Trips
Otherside Test Events
LOTM Guides & Info
Basics Guide
Hunting Guide
Farming Guide
Enchanting Guide
Game Updates
Oda Information
Quick References
Koda Weapons
Oda Abilities Table
Oda Stats Table
Tools
What links here
Related changes
Special pages
Page information
Page values