luau 0.732.0

Safe lifetime-bound Rust embedding API for the Luau runtime
use crate::error::Error;
use crate::value::{FromLua, FromLuaMulti, IntoLua, IntoLuaMulti, Value};

pub(crate) mod private {
    pub trait Sealed {}
}

/// A table, userdata, class, or object value that supports Luau object operations.
pub trait ObjectLike<'lua>: private::Sealed {
    /// Gets a value through the object's indexing semantics.
    fn get<V>(&self, key: impl IntoLua<'lua>) -> Result<V, Error>
    where
        V: FromLua<'lua>;

    /// Sets a value through the object's indexing semantics.
    fn set(&self, key: impl IntoLua<'lua>, value: impl IntoLua<'lua>) -> Result<(), Error>;

    /// Calls the object using its `__call` metamethod.
    fn call<R>(&self, args: impl IntoLuaMulti<'lua>) -> Result<R, Error>
    where
        R: FromLuaMulti<'lua>;

    /// Calls a function obtained from the object, passing the object as its first argument.
    fn call_method<R>(&self, name: &str, args: impl IntoLuaMulti<'lua>) -> Result<R, Error>
    where
        R: FromLuaMulti<'lua>;

    /// Calls a function obtained from the object without passing the object as an argument.
    fn call_function<R>(&self, name: &str, args: impl IntoLuaMulti<'lua>) -> Result<R, Error>
    where
        R: FromLuaMulti<'lua>;

    /// Converts the object to a string using its `__tostring` metamethod when present.
    fn to_string(&self) -> Result<String, Error>;

    /// Roots the object as a general Lua value.
    fn to_value(&self) -> Result<Value<'lua>, Error>;
}