lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


I'm writing a simple tree checker for deep nested tables with unorthodox keys (functions, tables, userdata, threads).

I'm testing it against Lua from versions 5.1 to 5.4 but the call stack is inconsistent in newer versions while Lua 5.1 is showing the expected stack.

I wrote a simple reproducible test:

function mt:check(k)
  local current = self.path[#self.path]
  if type(current) ~= 'table' then
    error('actually node is not a table',2)
  end
  table.insert(self.path, current[k])
  return self
end

local function check(t)
  return setmetatable({path={t}}, mt)
end

local list = {a = { b= 1 }}
check(list) -- line 18
  :check('a')
    :check('b')
      :check('c') -- line 21

It is expected that the call to ":check('c')" throws an error. This call is on line 21.

Running on Lua 5.1:

lua5.1: /tmp/x.lua:21: actual node is not a table
stack traceback:
        [C]: in function 'error'
        /tmp/x.lua:7: in function 'check'
        /tmp/x.lua:21: in main chunk
        [C]: ?

lua5.1: /tmp/x.lua:21: actually node is not a table
stack traceback:
        [C]: in function 'error'
        /tmp/x.lua:7: in function 'check'
        /tmp/x.lua:21: in main chunk
        [C]: ?

lua5.4: /tmp/x.lua:18: actual node is not a table
stack traceback:
	[C]: in function 'error'
	/tmp/x.lua:7: in method 'check'
	/tmp/x.lua:18: in main chunk
	[C]: in ?

See that on Lua 5.2+ (5.4 inclusive) points to the wrong line.
A workaround is to keep the value of each call on a variable, and use it to call the next step. While I can do this, It is counterintuitive and even make debugging a hard work prone to error.

Thanks
_________________
Thadeu de Paula
https://codeberg.org/waxlab
https://codeberg.org/arkt8