local M= {} local private= {} -- holds private data of all objecs in subtables -- Class Point: -- local Point_proto= {} -- Class prototype function Point_proto:set(x,y) local priv= private[self] priv.x= x priv.y= y end function Point_proto:get() local priv= private[self] return priv.x, priv.y end function Point_proto:tostring() local priv= private[self] return "["..priv.x.."|"..priv.y.."]" end Point_proto.__index = Point_proto Point_proto.__newindex= function() assert(false,"object is write-protected") end setmetatable(Point_proto, { -- ensure read protection for Point and all childs __index= function() assert(false, "object is read-protected") end }) function M.new_Point(x,y) -- constructor local instance= {} setmetatable(instance, Point_proto) private[instance]= {} -- create private part of object instance:set(x,y) return instance end return M