Skip to content

MDL Pattern | Interface

Mason Bially edited this page Oct 3, 2013 · 2 revisions

The following MDL pattern is a holdover until an MDL object system extension exists. Languages which don't support that extension will have to use something like the following anyway.

Pattern

The names object, internal, and this below are conventional.

# The declaration of the struct holding the interface information.
TypeDeclaration("IExampleStruct", TypeStruct([
    # The pointer to the object that this interface came from. (i.e. the object of the class providing this interface)
    TypeStructElement("object", TypeNone.Pointer()),
    # A pointer for the implementation of this interface to use.
    TypeStructElement("internal", TypeNone.Pointer()),

    # Function pointers for the features the interface provides
    DocumentationAttribute("""
    Does some stuff.
    """)(
    TypeStructElement("do_thing", TypeFunction(
        TypeNone, [
            # Every function must have a this pointer which will get the instance of this struct the function was retrived from.
            TypeFunctionArgument("this", TypePointer("IExampleStruct")),
            TypeFunctionArgument("an_argument", TypePointer("FooStruct"))
        ]))),

    ...
])),

# The actual type passed in and out of functions.
TypeDeclaration("IExample", NamedType("IExampleStruct").Pointer()),

Clone this wiki locally