Skip to content

906 Functions And Method Calls ​

906-functions-method-calls.mc covers func, parameters, this, return, and method calls. Tutorial first use: 04-functions-and-reuse.

Syntax synopsis:

text
func ConnectAnode(signal)
{
    signal -> ANODE
    return this
}
func ConnectCathode(ground)
{
    CATHODE -> ground
}
INSTANCE.ConnectAnode(A).ConnectCathode(GND)

Bare component pin names select pins on the current instance. return this returns that instance, so .ConnectCathode(...) runs on the value returned by ConnectAnode(...). Tutorial example 042 uses the same method-chain pattern.

bash
eval "$(../mcc/scripts/mcc-slot.sh)"
MCC_SYSTEM_ROOT="$(cd .. && pwd)" "$MCC_BIN" --local parse 90-language-reference/906-functions-method-calls.mc --lib mcode --pass1 --pass2

Source ​

text
// Reference: Functions And Method Calls
// Focus: func parameters, this, return, and calling a component method.

component REF_LED
{
    name = "Reference LED"
    pins = [
        io [1, 2] = DIO{A, K}   // A = anode, K = cathode (DIO face adoption)
    ]

    func ConnectAnode(signal)
    {
        signal -> this.A
        return this
    }

    func ConnectCathode(ground)
    {
        this.K -> ground
    }
}

module main
{
    io GND
    io GPIO_STATUS

    REF_LED D_STATUS
    RES R_LIMIT(330R, 50V)

    GPIO_STATUS -> R_LIMIT.1
    D_STATUS.ConnectAnode(R_LIMIT.2).ConnectCathode(GND)
}

MCode Bench is the public face of the MCode stack. Closed capabilities are served through the MCode gateway.