[−][src]Struct glsp_engine::RClassBuilder
Builder used to define GameLisp bindings for a particular Rust type.
By default, GameLisp code is forced to treat rdata
as a black box. They have no methods, no
property getters or setters, no class name (so predicates like is?
will always return false),
they can't be cloned, and they can't be compared for equality.
RClassBuilder
provides methods to override all of the above.
//provide some basic bindings for ggez::Image RClassBuilder::<Image>::new() .prop_get("width", &Image::width) .prop_get("height", &Image::height) .met("draw", &|image: &Image, ctx: &mut Context| { image.draw(ctx, DrawParam::default()) }) .build(); //now, whenever an rdata is constructed from a ggez::Image, //it will have a GameLisp api glsp::bind_global("boulder", Image::new(ctx, "boulder.png")?)?; eval!(" (prn [boulder 'width] [boulder 'height]) (.draw boulder) ")?;
Implementations
impl<T: 'static> RClassBuilder<T>
[src]
pub fn new() -> RClassBuilder<T>
[src]
pub fn name<S: ToSym>(self, name: S) -> RClassBuilder<T>
[src]
Assigns a name which will be used by the functions is?
and class-of
to identify
this RClass
.
Every RClass
must have a name, and that name must be globally unique within a particular
Runtime
. For example, if you have two Rust types audio::Clip
and video::Clip
, they
can't both be named Clip
.
RClassBuilder::new()
will attempt to auto-generate an unprefixed name by processing the
result of type_name::<T>()
.
This will silently fail for generic types, references, arrays, tuples, and types with
lifetime parameters; for those types, you must provide a name manually.
This method panics if name
is not a valid symbol.
pub fn met<S, ArgsWithTag, Ret, F>(self, name: S, f: F) -> RClassBuilder<T> where
S: ToSym,
Wrapper<ArgsWithTag, Ret, F>: WrappedCall + 'static,
[src]
S: ToSym,
Wrapper<ArgsWithTag, Ret, F>: WrappedCall + 'static,
Registers a method.
Firstly, the f
function is promoted to an RFn
, as though by calling
glsp::rfn
. Whenever GameLisp code attempts to invoke the specified method
on an rdata
of type T
, that RFn
will be invoked, passing in the rdata
as its first
argument.
Panics if a property or method has already been associated with the given name,
or if name
is not a valid symbol.
Due to a rustc bug, the f
parameter must
be passed as a reference or a Box
; it can't be directly passed by value.
pub fn prop_get<S, ArgsWithTag, Ret, F>(self, name: S, f: F) -> RClassBuilder<T> where
S: ToSym,
Wrapper<ArgsWithTag, Ret, F>: WrappedCall + 'static,
[src]
S: ToSym,
Wrapper<ArgsWithTag, Ret, F>: WrappedCall + 'static,
Registers a property getter.
Firstly, the f
function is promoted to an RFn
, as though by calling
glsp::rfn
. Whenever GameLisp code attempts to access the specified property
on an rdata
of type T
, that RFn
will be invoked, passing in the rdata
as its only
argument.
Panics if a property getter or method has already been associated with the given name,
or if name
is not a valid symbol.
Due to a rustc bug, the f
parameter must
be passed as a reference or a Box
; it can't be directly passed by value.
pub fn prop_set<S, ArgsWithTag, Ret, F>(self, name: S, f: F) -> RClassBuilder<T> where
S: ToSym,
Wrapper<ArgsWithTag, Ret, F>: WrappedCall + 'static,
[src]
S: ToSym,
Wrapper<ArgsWithTag, Ret, F>: WrappedCall + 'static,
Registers a property setter.
Firstly, the f
function is promoted to an RFn
, as though by calling
glsp::rfn
. Whenever GameLisp code attempts to assign to the specified
property on an rdata
of type T
, that RFn
will be invoked, passing in the rdata
as
its first argument and the assigned value as its second argument.
Panics if a property setter or method has already been associated with the given name,
or if name
is not a valid symbol.
Due to a rustc bug, the f
parameter must
be passed as a reference or a Box
; it can't be directly passed by value.
pub fn trace(self, f: fn(_: &T, _: &mut GcVisitor<'_>)) -> RClassBuilder<T>
[src]
Registers a function used by the garbage collector to visit any Gc
pointers owned by this object.
If an RData
type stores any Gc
pointers, but it doesn't specify an accurate trace
method
which visits all of its owned Gc
pointers, then the pointed-to objects may be unpredictably
deallocated, causing Gc::upgrade
to fail.
The callback should only iterate through any Gc
s, GcVal
s and RGc
s which are directly
owned by the object, passing each of them to the GcVisitor
.
Interacting with GameLisp in any other way is likely to trigger a panic.
See also glsp::write_barrier
.
struct UnitList { units: Vec<RGc<Unit>> } impl UnitList { fn trace(&self, visitor: &mut GcVisitor) { for unit in &self.units { visitor.visit_rgc(unit); } } fn add_unit(&mut self, unit: RRoot<Unit>) { self.units.push(unit.downgrade()); glsp::write_barrier(self); } } RClassBuilder::<UnitList>::new() .trace(UnitList::trace) .build();
pub fn build(self)
[src]
Finalizes the RClass
and registers it with the active Runtime
.
Panics if the RClass
's name has not been specified, if its name has already been used
by another RClass
, or if another RClass
for T
has already been registered.
Auto Trait Implementations
impl<T> !RefUnwindSafe for RClassBuilder<T>
[src]
impl<T> !Send for RClassBuilder<T>
[src]
impl<T> !Sync for RClassBuilder<T>
[src]
impl<T> Unpin for RClassBuilder<T> where
T: Unpin,
[src]
T: Unpin,
impl<T> !UnwindSafe for RClassBuilder<T>
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Erased for T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,