#Metatables and types

1 messages · Page 1 of 1 (latest)

pine flame
#
--!strict
--!native
--!optimize 2

export type u8  = number
export type u16 = number
export type u32 = number

local ControlBus = {}
ControlBus.__index = ControlBus

export type ControlBus =
    typeof(setmetatable({} :: {
        Signals:  ControlLanes,
        _Values:  ControlLanes,
        _Proxy:   { [string]: SignalProxyCallback }
    }, ControlBus)) &
{
    SetSignals:
        (signals: ControlLanes) -> (),
    GetSignals:
        () -> (ControlLanes)
}

export type SignalProxyCallback
    = (new: u8, old: u8) -> ()

export type ControlLanes = {
    ADS:    u8, W_R:    u8, M_IO:   u8, D_C:    u8, LOCK:   u8,
    READY:  u8, NA:     u8, BS16:   u8, HOLD:   u8, HLDA:   u8, INTR:   u8, NMI:    u8,
    PEREQ:  u8, BUSY:   u8,
    ERROR:  u8, RESET:  u8, CLK2:   u8,
}

function ControlBus.new(): ControlBus
    local Signals: ControlLanes = {
        ADS     = 0 :: u8,  W_R     = 0 :: u8,  M_IO    = 0 :: u8,  D_C     = 0 :: u8,  LOCK    = 0 :: u8,
        READY   = 0 :: u8,  NA      = 0 :: u8,  BS16    = 0 :: u8,  HOLD    = 0 :: u8,  HLDA    = 0 :: u8,
        INTR    = 0 :: u8,  NMI     = 0 :: u8,  PEREQ   = 0 :: u8,  BUSY    = 0 :: u8,  ERROR   = 0 :: u8,
        RESET   = 0 :: u8,  CLK2    = 0 :: u8,
    }

    return setmetatable({
        _Values = Signals :: ControlLanes,
        _Proxy  = {} :: { [string]: SignalProxyCallback },
        Signals = setmetatable({}, {
            __index = function(_, key)
                return Signals[key]
            end,
        }) :: ControlLanes,
    }, ControlBus) :: ControlBus
end

any idea why this keeps happening?

stuck ventureBOT
#

studio** You are now Level 1! **studio

pine flame
#

/close

#

!close