Page 1 of 2

Zerobrane & 30log/middle class

Posted: Fri May 08, 2015 12:06 am
by pajh
I'm using Zerobrane and liking the debugger, though just recently I decided to add one of the OO wrappers to tidy up my code - at this stage I've used 30log and middleclass, both having the same problem - zerobrane watch window no longer shows any of the contents of these 'objects' - just the text "instance of X'

Whereas my homemade "classes" which just used setmetatable() and __index to mimic "class functions" showed up perfectly in the ZB watch window.

So is there another simple OO wrapper that does work with ZB debugger or is there a simple hack I can do to one of these to make it work>?

Re: Zerobrane & 30log/middle class

Posted: Fri May 08, 2015 2:01 am
by I~=Spam
Here is a link to the "clean" version of 30log (it isn't condensed into 30 lines). I have selected a line. Comment this out and use this file. I think it will work then. :) https://github.com/Yonaba/30log/blob/ma ... an.lua#L73

Re: Zerobrane & 30log/middle class

Posted: Fri May 08, 2015 2:49 am
by cohadar
The best way to write clean code is to not use any OO.
Believe me I know, I write Java for a living.

Re: Zerobrane & 30log/middle class

Posted: Fri May 08, 2015 10:27 am
by pajh
I~=Spam wrote:Here is a link to the "clean" version of 30log (it isn't condensed into 30 lines). I have selected a line. Comment this out and use this file. I think it will work then. :) https://github.com/Yonaba/30log/blob/ma ... an.lua#L73
Thanks for that - removing that line didn't fix it - however removing the entire __tostring function just above it in baseMT as well as removing the line you pointed out seems to have fixed it - now i can see the table contents in ZB watches like a normal table.

Will post again when i've done a bit more if this change breaks anything

Re: Zerobrane & 30log/middle class

Posted: Fri May 08, 2015 10:47 am
by kikito
Hi there,

The same happens in middleclass. If you remove the __tostring function from the main Object class, it should work too.

BTW, I personally would *always* print the dump of the table, even if it has a tostring metamethod (in inspect.lua I print both things)

Re: Zerobrane & 30log/middle class

Posted: Fri May 08, 2015 11:19 am
by pajh
kikito wrote:Hi there,

The same happens in middleclass. If you remove the __tostring function from the main Object class, it should work too.

BTW, I personally would *always* print the dump of the table, even if it has a tostring metamethod (in inspect.lua I print both things)
sorry not sure what you mean - is there a setting I can change in Zerobrane to make it ignore the tostring and keep middleclass/30log unchanged but still see the contents/drill down in the ZB watch window?

Re: Zerobrane & 30log/middle class

Posted: Fri May 08, 2015 11:48 am
by kikito
pajh wrote:
kikito wrote:Hi there,

The same happens in middleclass. If you remove the __tostring function from the main Object class, it should work too.

BTW, I personally would *always* print the dump of the table, even if it has a tostring metamethod (in inspect.lua I print both things)
sorry not sure what you mean - is there a setting I can change in Zerobrane to make it ignore the tostring and keep middleclass/30log unchanged but still see the contents/drill down in the ZB watch window?
No, I mean that If I was the author of ZB, I would always dump the tables. I have not used it so I don't know its options.

Re: Zerobrane & 30log/middle class

Posted: Fri May 08, 2015 12:23 pm
by s-ol
kikito wrote:
pajh wrote:
kikito wrote:Hi there,

The same happens in middleclass. If you remove the __tostring function from the main Object class, it should work too.

BTW, I personally would *always* print the dump of the table, even if it has a tostring metamethod (in inspect.lua I print both things)
sorry not sure what you mean - is there a setting I can change in Zerobrane to make it ignore the tostring and keep middleclass/30log unchanged but still see the contents/drill down in the ZB watch window?
No, I mean that If I was the author of ZB, I would always dump the tables. I have not used it so I don't know its options.
I just opened #457 on github for this.

Re: Zerobrane & 30log/middle class

Posted: Sat May 09, 2015 12:44 am
by paulclinger
kikito wrote:No, I mean that If I was the author of ZB, I would always dump the tables. I have not used it so I don't know its options.
My previous (long) response got eaten by some "maintenance" message on the server, so I'll keep this one short ;).

ZBS doesn't dump the table by default, because metatables can be used with things like userdata, and the assumption is that if someone wanted to have __tostring, this is the results that users want.

The idea to show both (__tostring and serialization result) looks interesting, but it may end up complicating things (and duplicating elements if some of them are already returned by __tostring.

As a quick workaround, you may add __serialize method that simply returns the same table, which will be serialized as a regular table. Something like this may work (not tested): __serialize = function(t) return t end

I do consider adding a way to suppress all metatable processing, so a better option may be available in the future. Paul.

Re: Zerobrane & 30log/middle class

Posted: Sat May 09, 2015 3:23 am
by I~=Spam
Ok I suppose that makes sense. Could you have that be optional in the config?

EDIT:
cohadar wrote:The best way to write clean code is to not use any OO.
Believe me I know, I write Java for a living.
Considering that java forces you to use java I think you might want to reconsider your programming choice...

If that is how you feel about OOP you probably don't know how to use it. Pure ANSI C guys tend to not use OOP not because it is awful (in fact they might prefer it) but because it can be significantly faster to write data-oriented code. This is hardly a consideration with java because objects are forced on you anyway so I just think you don't understand OOP.

It is interesting but a C programer using tables and passing a pointer to the table as the first arg to a set of functions can create a form of OOP. This is actually exactly what lua does. Why do they do this? The code is easier to read, maintain, and if they are careful also just as fast by being cache friendly.

So... again.... I don't think you fundamentally understand OOP...