use mlua::{AnyUserData, FromLua, FromLuaMulti, IntoLua, IntoLuaMulti, Lua};
#[cfg(feature = "async")]
use mlua::{UserDataRef, UserDataRefMut};
use crate::{MaybeSend, typed::IntoDocComment};
use super::{Typed, TypedMultiValue, Type};
mod wrapped;
mod standard;
pub use wrapped::WrappedBuilder;
pub use standard::{TypedClassBuilder, TypedClass};
pub trait TypedUserData: Sized {
#[allow(unused_variables)]
fn add_documentation<F: TypedDataDocumentation<Self>>(docs: &mut F) {}
#[allow(unused_variables)]
fn add_methods<T: TypedDataMethods<Self>>(methods: &mut T) {}
#[allow(unused_variables)]
fn add_fields<F: TypedDataFields<Self>>(fields: &mut F) {}
}
pub trait TypedDataDocumentation<T: TypedUserData> {
fn add(&mut self, doc: &str) -> &mut Self;
}
pub trait TypedDataMethods<T> {
fn add_method<S, A, R, M>(&mut self, name: S, method: M)
where
S: Into<String>,
A: FromLuaMulti + TypedMultiValue,
R: IntoLuaMulti + TypedMultiValue,
M: 'static + MaybeSend + Fn(&Lua, &T, A) -> mlua::Result<R>;
fn add_method_mut<S, A, R, M>(&mut self, name: S, method: M)
where
S: Into<String>,
A: FromLuaMulti + TypedMultiValue,
R: IntoLuaMulti + TypedMultiValue,
M: 'static + MaybeSend + FnMut(&Lua, &mut T, A) -> mlua::Result<R>;
#[cfg(feature = "async")]
fn add_async_method<S: Into<String>, A, R, M, MR>(&mut self, name: S, method: M)
where
T: 'static,
M: Fn(Lua, UserDataRef<T>, A) -> MR + MaybeSend + 'static,
A: FromLuaMulti + TypedMultiValue,
MR: std::future::Future<Output = mlua::Result<R>> + MaybeSend + 'static,
R: IntoLuaMulti + TypedMultiValue;
#[cfg(feature = "async")]
fn add_async_method_mut<S: Into<String>, A, R, M, MR>(&mut self, name: S, method: M)
where
T: 'static,
M: Fn(Lua, UserDataRefMut<T>, A) -> MR + MaybeSend + 'static,
A: FromLuaMulti + TypedMultiValue,
MR: std::future::Future<Output = mlua::Result<R>> + MaybeSend + 'static,
R: IntoLuaMulti + TypedMultiValue;
fn add_function<S, A, R, F>(&mut self, name: S, function: F)
where
S: Into<String>,
A: FromLuaMulti + TypedMultiValue,
R: IntoLuaMulti + TypedMultiValue,
F: 'static + MaybeSend + Fn(&Lua, A) -> mlua::Result<R>;
fn add_function_mut<S, A, R, F>(&mut self, name: S, function: F)
where
S: Into<String>,
A: FromLuaMulti + TypedMultiValue,
R: IntoLuaMulti + TypedMultiValue,
F: 'static + MaybeSend + FnMut(&Lua, A) -> mlua::Result<R>;
#[cfg(feature = "async")]
fn add_async_function<S, A, R, F, FR>(&mut self, name: S, function: F)
where
S: Into<String>,
A: FromLuaMulti + TypedMultiValue,
R: IntoLuaMulti + TypedMultiValue,
F: 'static + MaybeSend + Fn(Lua, A) -> FR,
FR: 'static + MaybeSend + std::future::Future<Output = mlua::Result<R>>;
fn add_meta_method<A, R, M>(&mut self, meta: impl Into<String>, method: M)
where
A: FromLuaMulti + TypedMultiValue,
R: IntoLuaMulti + TypedMultiValue,
M: 'static + MaybeSend + Fn(&Lua, &T, A) -> mlua::Result<R>;
fn add_meta_method_mut<A, R, M>(&mut self, meta: impl Into<String>, method: M)
where
A: FromLuaMulti + TypedMultiValue,
R: IntoLuaMulti + TypedMultiValue,
M: 'static + MaybeSend + FnMut(&Lua, &mut T, A) -> mlua::Result<R>;
fn add_meta_function<A, R, F>(&mut self, meta: impl Into<String>, function: F)
where
A: FromLuaMulti + TypedMultiValue,
R: IntoLuaMulti + TypedMultiValue,
F: 'static + MaybeSend + Fn(&Lua, A) -> mlua::Result<R>;
fn add_meta_function_mut<A, R, F>(&mut self, meta: impl Into<String>, function: F)
where
A: FromLuaMulti + TypedMultiValue,
R: IntoLuaMulti + TypedMultiValue,
F: 'static + MaybeSend + FnMut(&Lua, A) -> mlua::Result<R>;
fn document(&mut self, doc: impl IntoDocComment) -> &mut Self;
fn param(&mut self, name: impl std::fmt::Display, doc: impl IntoDocComment) -> &mut Self;
fn param_as(&mut self, ty: impl Into<Type>, name: impl std::fmt::Display, doc: impl IntoDocComment) -> &mut Self;
fn ret(&mut self, doc: impl IntoDocComment) -> &mut Self;
fn ret_as(&mut self, ty: impl Into<Type>, doc: impl IntoDocComment) -> &mut Self;
fn index<I: Typed>(&mut self, idx: isize, doc: impl IntoDocComment) -> &mut Self;
fn index_as(&mut self, idx: isize, ty: impl Into<Type>, doc: impl IntoDocComment) -> &mut Self;
}
pub trait TypedDataFields<T> {
fn document(&mut self, doc: impl IntoDocComment) -> &mut Self;
fn coerce(&mut self, ty: impl Into<Type>) -> &mut Self;
fn add_field<V>(&mut self, name: impl Into<String>, value: V)
where
V: IntoLua + Clone + 'static + Typed;
fn add_field_method_get<S, R, M>(&mut self, name: S, method: M)
where
S: Into<String>,
R: IntoLua + Typed,
M: 'static + MaybeSend + Fn(&Lua, &T) -> mlua::Result<R>;
fn add_field_method_set<S, A, M>(&mut self, name: S, method: M)
where
S: Into<String>,
A: FromLua + Typed,
M: 'static + MaybeSend + FnMut(&Lua, &mut T, A) -> mlua::Result<()>;
fn add_field_method_get_set<S, R, A, GET, SET>(&mut self, name: S, get: GET, set: SET)
where
S: Into<String>,
R: IntoLua + Typed,
A: FromLua + Typed,
GET: 'static + MaybeSend + Fn(& Lua, &T) -> mlua::Result<R>,
SET: 'static + MaybeSend + Fn(& Lua, &mut T, A) -> mlua::Result<()>;
fn add_field_function_get<S, R, F>(&mut self, name: S, function: F)
where
S: Into<String>,
R: IntoLua + Typed,
F: 'static + MaybeSend + Fn(&Lua, AnyUserData) -> mlua::Result<R>;
fn add_field_function_set<S, A, F>(&mut self, name: S, function: F)
where
S: Into<String>,
A: FromLua + Typed,
F: 'static + MaybeSend + FnMut(&Lua, AnyUserData, A) -> mlua::Result<()>;
fn add_field_function_get_set<S, R, A, GET, SET>(&mut self, name: S, get: GET, set: SET)
where
S: Into<String>,
R: IntoLua + Typed,
A: FromLua + Typed,
GET: 'static + MaybeSend + Fn(&Lua, AnyUserData) -> mlua::Result<R>,
SET: 'static + MaybeSend + Fn(&Lua, AnyUserData, A) -> mlua::Result<()>;
fn add_meta_field<V>(&mut self, meta: impl Into<String>, value: V)
where V: IntoLua + Typed + 'static;
fn add_meta_field_with<R, F>(&mut self, meta: impl Into<String>, f: F)
where
F: 'static + MaybeSend + Fn(&Lua) -> mlua::Result<R>,
R: IntoLua + Typed + 'static;
}