2000DTM / bizhawk

Automatically exported from code.google.com/p/bizhawk
0 stars 0 forks source link

Vague Lua exception. #87

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Load the following Lua script: 

local exited = false
local room = memory.readbyte(0x0154)
local x
local y

while true do
    local key = {}
    local text = memory.readbyte(0x506)
    if text > 36 then
        key.A = 1
    end
    joypad.set(1, key)

    local newx = memory.readbyte(0x0032) + (memory.readbyte(0x0032) * 256)
    local newy = memory.readbyte(0x0034) + (memory.readbyte(0x0035) * 256)
    newx = (newx - 8) / 16
    newy = (newy - 8) / 16
    if x == nil then
        x = newx
        y = newy
    end
    gui.text(0, 8, '          ')
    gui.text(0, 8, newx .. ', ')
    gui.text(60, 8, newy)
    gui.text(0, 16, '          ')
    gui.text(0, 16, (newx - x) .. ', ', 'green')
    gui.text(60, 16, newy - y, 'green')
    x = newx
    y = newy

    local newroom = memory.readbyte(0x0154)
    if room ~= newroom then
        exited = movie.framecount()
    end
    if exited ~= false then
        gui.text(0, 24, 'Exited: ' .. exited)
        if movie.framecount() == exited + 120 then
            exited = false
        end
    end
    room = newroom

    local sub = memory.readbyte(0x7093)
    gui.text(165, 8, 'Subpixel value: ' .. sub)
    if sub < 20 then
       gui.text(165, 16, 'Turn now!')
    end
    emu.frameadvance()
end

What is the expected output? What do you see instead?
I get the error message "LuaInterface.LuaScriptException: table". Perhaps I 
need to take additional steps to port it from FCEUX to BizHawk, but this 
exception is far too vague to work off of.

What version of the product are you using? On what operating system?
r2968

Original issue reported on code.google.com by brandman...@gmail.com on 10 Sep 2012 at 9:02

GoogleCodeExporter commented 9 years ago

Original comment by adeli...@tasvideos.org on 17 Sep 2012 at 10:47

GoogleCodeExporter commented 9 years ago
The script doesn't work because joypad.set() is invoked incorrectly.  Doesn't 
seem like http://tasvideos.org/Bizhawk/LuaFunctions.html is correct on this 
matter, so here's the function:

nil joypad.set (table buttons, number controller)

any non-nil non-false values in buttons are set to clicked in the next frame.  
for a list of appropriate keys, try joypad.get()  this function can't toggle or 
unset an input.

controller should be a number corresponding to player number, or nil for 
"system" controls (reset buttons mostly)

As far as fixing the vague error message goes, for the technically inclined:  
LuaInterface throws a LuaScriptException with Source == null.  I didn't think 
it could do this and don't know how to remedy the problem.  Normally, Source 
would tell us where the problem occurred...

Original comment by goyu...@gmail.com on 23 Sep 2012 at 10:13

GoogleCodeExporter commented 9 years ago
need to add stacktrace printing error handler to pcall

Original comment by zero...@zeromus.org on 23 Sep 2012 at 10:17

GoogleCodeExporter commented 9 years ago
Also, this exception in particular occurs because a table is attempted to get 
coerced to an int by LuaInt (or the other way around) for the argument to 
joypad_set but LuaInterface just barfs and explodes. still, with a stacktrace, 
we couldve seen where that happened from.

Original comment by zero...@zeromus.org on 23 Sep 2012 at 10:21

GoogleCodeExporter commented 9 years ago

Original comment by adeli...@tasvideos.org on 29 Sep 2012 at 2:36

GoogleCodeExporter commented 9 years ago
Since this issue was opened, a stack trace has been added to lua exceptions, 
and this script outputs the correct error "Invalid arguments to method call" 
and a line number in the script.

Original comment by adeli...@tasvideos.org on 27 Apr 2014 at 12:42