luau-vm 0.732.0

Pure-Rust Luau virtual machine, garbage collector, and standard libraries
Documentation
use crate::state::{
    THREAD_STATUS_ERR_ERR, THREAD_STATUS_ERR_MEM, THREAD_STATUS_ERR_RUN, THREAD_STATUS_ERR_SYNTAX,
};

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[repr(u8)]
pub enum VmError {
    Runtime,
    Syntax,
    Memory,
    ErrorHandler,
}

impl VmError {
    pub(crate) const fn status(self) -> i32 {
        match self {
            Self::Runtime => THREAD_STATUS_ERR_RUN as i32,
            Self::Syntax => THREAD_STATUS_ERR_SYNTAX as i32,
            Self::Memory => THREAD_STATUS_ERR_MEM as i32,
            Self::ErrorHandler => THREAD_STATUS_ERR_ERR as i32,
        }
    }
}

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[repr(u8)]
pub enum VmControl {
    Yield,
    Break,
}

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum VmExit {
    Error(VmError),
    Control(VmControl),
}

impl From<VmError> for VmExit {
    fn from(error: VmError) -> Self {
        Self::Error(error)
    }
}

impl From<VmControl> for VmExit {
    fn from(control: VmControl) -> Self {
        Self::Control(control)
    }
}

pub type VmResult<T = ()> = Result<T, VmExit>;

pub type VmErrorResult<T = ()> = Result<T, VmError>;