tag:blogger.com,1999:blog-8807114244208457198.post4344930286832914534..comments2012-04-22T20:14:05.012-07:00Comments on tekarak: DisplayObject inheritance in CoronaE Herrmannhttp://www.blogger.com/profile/06498601922990185572noreply@blogger.comBlogger3125tag:blogger.com,1999:blog-8807114244208457198.post-90490967210399461832012-04-22T20:14:05.012-07:002012-04-22T20:14:05.012-07:00what about a non-metatable based approach like her...what about a non-metatable based approach like here?<br /><br /> http://jessewarden.com/2011/10/lua-classes-and-packages-in-corona.html<br /><br />Would this give the same results and be a bit easier to implement / read.Greg Hauptmannhttps://www.blogger.com/profile/05928229527681450049noreply@blogger.comtag:blogger.com,1999:blog-8807114244208457198.post-15698835007971326752012-02-11T11:13:12.684-08:002012-02-11T11:13:12.684-08:00Here's how I got it to work with an __index fu...Here's how I got it to work with an __index function that looks like this.<br /><br />function(_t, _k)<br /> if disp[_k] then<br /> if type(disp[_k]) == 'function' then<br /> return function(...) arg[1] = disp; disp[_k](unpack(arg)) end<br /> else<br /> return disp[_k]<br /> end<br /> end<br /> return nil<br />endDonhttps://www.blogger.com/profile/03301339342733248382noreply@blogger.comtag:blogger.com,1999:blog-8807114244208457198.post-80792372015601210552012-02-11T11:07:43.327-08:002012-02-11T11:07:43.327-08:00Does this method actually work? I get an error wh...Does this method actually work? I get an error when I try to access a display object method. <br /><br />For instance if I create a newCircle and then try to setFillColor on it via the proxy I get a Proxy is nil error.<br /><br />Example:<br /><br />local function newCircle(_x, _y, _radius)<br /> local c = display.newCircle(_x, _y, _radius)<br /> local proxy = {}<br /> local mt = {<br /> __index = function(_t, _k)<br /> return c[_k]<br /> end<br /> , __newindex = function(_t, _k, _v)<br /> c[_k] = _v<br /> end<br /> }<br /> setmetatable(proxy, mt)<br /> return proxy<br />end<br /><br />local circle = newCircle(0, 0, 100)<br />circle:setFillColor(255, 0, 0)<br /><br />-- you get an error because the method setFillColor is returned for the display object but circle is applied as the first parameter which throws the error.Donhttps://www.blogger.com/profile/03301339342733248382noreply@blogger.com