[][src]Struct glsp::RClassBuilder

#[must_use]pub struct RClassBuilder<T> { /* fields omitted */ }

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> RClassBuilder<T> where
    T: 'static, 
[src]

pub fn new() -> RClassBuilder<T>[src]

pub fn name<S>(self, name: S) -> RClassBuilder<T> where
    S: ToSym
[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,
    Wrapper<ArgsWithTag, Ret, F>: 'static, 
[src]

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,
    Wrapper<ArgsWithTag, Ret, F>: 'static, 
[src]

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,
    Wrapper<ArgsWithTag, Ret, F>: 'static, 
[src]

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 Gcs, GcVals and RGcs 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]

impl<T> !UnwindSafe for RClassBuilder<T>[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Erased for T

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> IntoElement<Slot> for T where
    T: IntoVal
[src]

impl<T> IntoVal for T where
    T: StaticMarker, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.