thegrb93 / StarfallEx

Starfall, but with active development and more features. Write Garry's mod chips similar to E2, but in lua
https://discord.gg/yFBU8PU
Other
199 stars 108 forks source link

stack reports wrong function information #903

Open XAYRGA opened 4 years ago

XAYRGA commented 4 years ago

If a function is a single line long and encounters an error, the stacktrace will depict the actual function's details instead of the function which actually errored.

  function ramGet16(addr)
        return bit.bor( bit.lshift(RAM[addr] , 8), RAM[addr + 1])
    end

Hook 'tick' errored with: SF:chip8.txt:223: bad argument #2 to 'ramGet16' (number expected, got nil)
stack traceback:
    [C]: in function 'ramGet16'
    SF:chip8.txt:223: in function 'emulate'
    SF:chip8.txt:165: in function <SF:chip8.txt:155>

Whereas the expected result

 function ramGet16(addr)
       local val = bit.bor( bit.lshift(RAM[addr] , 8), RAM[addr + 1])
       return val
 end 

Hook 'tick' errored with: SF:chip8.txt:205: bad argument #2 to 'bor' (number expected, got nil)
stack traceback:
    [C]: in function 'bor'
    SF:chip8.txt:205: in function 'ramGet16'
    SF:chip8.txt:224: in function 'emulate'
    SF:chip8.txt:165: in function <SF:chip8.txt:155>

In the first, the error is occurring in "bor" but it's instead reporting ramGet16

thegrb93 commented 3 years ago

@XAYRGA This might be why, tail calls don't use stack. https://www.lua.org/pil/6.3.html