Squirrel supports implicit delegation. Every table or userdata can have a parent table (delegate). A parent table is a normal table that allows the definition of special behaviors for his child. When a table (or userdata) is indexed with a key that doesn’t correspond to one of its slots, the interpreter automatically delegates the get (or set) operation to its parent.
Entity <- { } function Entity::DoStuff() { ::print(_name); } local newentity=delegate Entity : { _name=”I’m the new entity” } newentity.DoStuff(); //prints “I’m the new entity”
The parent of a table can be retreived through keyword parent. parent is a 'pseudo slot'. The parent slot cannot be set, the delegete statement has to be used instead.
local thedelegate = newentity.parent;