[ZeroBrane Studio] Re: Debugging interoperation with middleclass.lua

  • From: Rob Probin <rob.probin@xxxxxxxxx>
  • To: zerobrane@xxxxxxxxxxxxx
  • Date: Wed, 12 Mar 2014 22:57:17 +0000



On 12/03/2014 22:51, Rob Probin wrote:

What do you do to get this error? I tried the following (including the
earlier fix for __serialize):

local Person = class('Person')
print(#Person)

And it prints 0 without any errors.

In the remote console, whilst running my code (at a breakpoint) print(#Person) and print(pairs(Person)) work for me as well. But why wouldn't it call the metamethods? (maybe I'm missing something obvious...)


Because it's using the Class metatable not the object metatable....
e.g. print(Person)

shows: "class Person"

Rather than

"instance of Person"

Try:
test = Person()
print(tostring(test))
    "instance of class Person"
print(test)
.../middleclass.lua:66: class Person doesn't implement metamethod '__len'




Other related posts: