-- shape as base class: shape_proto= {} function shape_proto:tostring() return "["..self.width.."|"..self.height.."]" end -- rectangle prototype inherits from shape: rectangle_proto= {} setmetatable(rectangle_proto, { __index=shape_proto }) -- rectangle constructor: function new_rectangle(width, height) rectangle= {width= width, height= height} setmetatable(rectangle, { __index=rectangle_proto, __tostring=rectangle_proto.tostring }) return rectangle end -- rectangle usage: rectangle= new_rectangle(3,4) print(rectangle:tostring()) --> [3|4] print(rectangle) --> [3|4]