Modules:
Code: Select all
;-- Geometry
DeclareModule Geometry
Structure Point2i
x.l
y.l
EndStructure
Structure Point2f
x.f
y.f
EndStructure
EndDeclareModule
;-- Polygon
DeclareModule Polygon2i
#MaxSize=$FFFFFFFF
Structure Point Extends Geometry::Point2i
EndStructure
Macro POINT_ARRAY
Point[]
EndMacro
Interface IObject
Declare.l size()
Declare.*POINT_ARRAY toPoints()
Declare draw()
EndInterface
Declare.IObject fromPointXY(i...)
EndDeclareModule
DeclareModule Polygon2f
#MaxSize=$FFFFFFFF
Structure Point Extends Geometry::Point2f
EndStructure
Macro POINT_ARRAY
Point[]
EndMacro
Interface IObject
Declare.l size()
Declare.*POINT_ARRAY toPoints()
Declare draw()
EndInterface
Declare.IObject fromPointXY(f...)
EndDeclareModule
;-- Triangle
DeclareModule Triangle2i
#Size=3
ModuleAlias Polygon Polygon2i
Structure Point Extends Geometry::Point2i
EndStructure
Macro POINT_ARRAY
Point[#Size]
EndMacro
Interface IObject
Declare.l size()
Declare.*POINT_ARRAY toPoints()
Declare.Polygon::IObject toPolygon()
EndInterface
Declare.IObject fromPointXY(x1.l, y1.l, x2.l, y2.l, x3.l, y3.l)
EndDeclareModule
DeclareModule Triangle2f
#Size=3
ModuleAlias Polygon Polygon2f
Structure Point Extends Geometry::Point2f
EndStructure
Macro POINT_ARRAY
Point[#Size]
EndMacro
Interface IObject
Declare.l size()
Declare.*POINT_ARRAY toPoints()
Declare.Polygon::IObject toPolygon()
EndInterface
Declare.IObject fromPointXY(x1.f, y1.f, x2.f, y2.f, x3.f, y3.f)
EndDeclareModule
;-- Shape
DeclareModule Shape2i
ModuleAlias Triangle Triangle2i
ModuleAlias Polygon Polygon2i
Structure Point Extends Geometry::Point2i
EndStructure
Interface ITriangle Extends Triangle::ITriangle
EndStructure
EndDeclareModule
DeclareModule Shape2f
ModuleAlias Triangle Triangle2f
ModuleAlias Polygon Polygon2f
Macro POINT_ARRAY
Polygon::POINT_ARRAY
EndMacro
Structure Point Extends Geometry::Point2f
EndStructure
Interface ITriangle Extends Triangle::ITriangle
EndStructure
EndDeclareModule
- Procedures can return pointers to arrays and structures, structure copies, and other interfaces
- Modules inherit scope
- ModuleAlias provides a way to re-declare a module with a different name
- Modules can contain other modules (declared or with ModuleAlias)
- Variadic arguments for procedures
Code: Select all
ModuleAlias Shape Shape2i
Define triangle.Shape::ITriangle
triangle=Shape::Triangle::fromPointXY(50,2, 98,86, 2,86)
Define pointArray.Shape::POINT_ARRAY
Define x
Define y
For i=1 To triangle\size()
pointArray=triangle\toPoints()
x=pointArray[i]\x
y=pointArray[i]\y
Debug Str(x)+" "+Str(y)
x=triangle\toPoints()[i]\x
y=triangle\toPoints()[i]\x
Debug Str(x)+" "+Str(y)
Next i
triangle\toPolygon()\draw()
- Support for variable arrays without the need for a structure
- Accessing an array returned from an interface
- Chain calling procedures from their return values: a()\b()\c()...