[ZeroBrane Studio] Debugging interoperation with middleclass.lua

  • From: Rob Probin <rob.probin@xxxxxxxxx>
  • To: zerobrane@xxxxxxxxxxxxx
  • Date: Wed, 12 Mar 2014 07:21:20 +0000

Hi,

This is just food for thought: I'm not suggesting a change to moddebug or ZBS.

So, as discussed before, I use middleclass.lua (mostly because I know how to use it) from https://github.com/kikito/middleclass

I've made some changes to middleclass.lua in order to see the contents of self, specifically added:

function Object:__serialize() return self end

And also modified this table (see the commented out lines):

Object.static.__metamethods = { '__add', '__call', '__concat', '__div', '__ipairs', '__le',
                                --'__len',
                                '__lt', '__mod', '__mul',
                                -- '__pairs',
                                '__pow', '__sub',
                                '__tostring', '__unm'}

This is used to define error messages for actions that need overriding to make sense for the class (I guess):

local function _createLookupMetamethod(aClass, name)
  return function(...)
    local method = aClass.super[name]
assert( type(method)=='function', tostring(aClass) .. " doesn't implement metamethod '" .. name .. "'" )
    return method(...)
  end
end

local function _setClassMetamethods(aClass)
  for _,m in ipairs(aClass.__metamethods) do
    aClass[m]= _createLookupMetamethod(aClass, m)
  end
end


This is necessary, I if remember, because mobdebug uses # (to limit bit arrays being sent to the debug server) and pairs (in order to get them out of a table). So this causes the metamethods to be called.

It's obviously possible for all user classes defined with middleclass to fix this, but it's just nice to see stuff work automatically when creating a class (I never get around to debug serialization).

I've considered that # maybe should be rawlen in mobdebug - but there might be side-effects I haven't considered with this approach. Additionally, I haven't got a way around the pairs metamethod.

Alternatively, maybe there are better changes to middleclass that I can do?


Regards,
Rob




Other related posts: