On Wed, Jun 5, 2013 at 11:22 PM, MZMcBride <z(a)mzmcbride.com> wrote:
The debug console seems finicky. Its line numbers never seem to make
sense.
The debug console probably could use some work. The way it works now,
it takes your past and current input, plugs all that into some
boilerplate to make a function, and then executes that function. The
line numbers reported for "Lua error in console input" therefore
depend on this boilerplate and on the lines you've previously entered
in the session.
It's also possible to break that boilerplate function, as you've seen below.
For example, I input this into a fresh console:
---
function p.asc(frame)
return frame.args[1]
end
---
Then I try ...
= print(p.asc())
Lua error in console input at line 6: attempt to index local 'frame' (a
nil value).
I have no idea what line 6 refers to. Earlier when I was testing it was
saying line 14.
It's referring to which line in that boilerplate function the "return
frame.args[1]" ended up at. Yes, that's not extremely helpful.
If I paste this into the console:
---
[SNIP]
return p
---
I get "Lua error in console input at line 18: 'end' expected (to close
'function' at line 1) near 'return'."
This is an example of breaking the boilerplate function. In Lua, it's
an error to have unreachable code after a return statement. When you
put "return p" into the debug console like that, the boilerplate
function winds up looking something like this:
function ( p )
local print = mw.log
-- Previous lines go here
mw.clearLogBuffer()
return p -- This is the line you entered
return nil, mw.getLogBuffer() -- This is boilerplate
end
Again, the console should probably be made more robust at some point
to avoid this sort of thing.
There's a note on the edit screen about using
mw.log(), but with various
inputs, I still can't seem to get anything working properly with the debug
console. For example:
---
function p.asc(frame)
t = {}
t['bar'] = 'baz'
mw.log(t)
return frame.args[1]
end
---
This prints nothing at all when pasted into the debug console.
That's because you're defining a function but not calling it (yet).
If I try "= print(t)" or
"print(t)" I get "nil".
Since 't' is a local variable inside the function, it's not defined
outside of it.
Is there a var_dump equivalent for Lua that can be
used?
Not yet.
--
Brad Jorsch
Software Engineer
Wikimedia Foundation