'Inner' Classes

Hi all,

Coming from an OO programming background, I find the use of inner classes, e.g. classes ‘nested’ inside other classes is a really useful technique for grouping functionality where you have a parent class that needs its own classes within its own context. Thats not a great explanation, so my example is that I’m writing a UI layout manager with panels that lay themselves out neatly. I want Panel objects that only have context within the UIManager class.

It appears that Codea supports this, which is very neat, e.g.:

UIManager = class()
function UIManager:init()
    self.panels = {}

function UIManager:addPanel(props)
    table.insert(self.panels, UIManager.Panel())

UIManager.Panel = class()

function UIManager.Panel:init(props)


function UIManager.Panel:draw()



The above is pseudo-code but gives the idea...

I didn't know you could do this, but its quite neat as you can keep a lot of context in one place and not have a proliferation of class tabs with tiny contextual classes...

May be common knowledge, but was new to me!


Basically, classes in Codea are glorified arrays. They’re arrays with meta tables that make is seem like a class, but nice.