Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement proper __eq override for schemas in Lua. #268

Merged
merged 1 commit into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 37 additions & 26 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions framework_crates/bones_scripting/src/lua.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use bones_lib::ecs::utils::*;
use parking_lot::Mutex;
use piccolo::{
registry::{Fetchable, Stashable},
AnyUserData, Closure, Context, Executor, FromValue, Fuel, Lua, ProtoCompileError,
StashedClosure, Table, Value,
AnyUserData, Closure, Context, Executor, FromValue, Lua, ProtoCompileError, StashedClosure,
Table, Value,
};
use send_wrapper::SendWrapper;
use std::{any::Any, rc::Rc, sync::Arc};
Expand Down
2 changes: 1 addition & 1 deletion framework_crates/bones_scripting/src/lua/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ pub fn env(ctx: Context) -> Table {
fn poll<'a>(
&mut self,
ctx: Context<'gc>,
_fuel: &mut Fuel,
_ex: piccolo::Execution<'gc, '_>,
mut stack: Stack<'gc, 'a>,
) -> Result<SequencePoll<'gc>, Error<'gc>> {
if self.mode == Mode::Init {
Expand Down
23 changes: 10 additions & 13 deletions framework_crates/bones_scripting/src/lua/bindings/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,19 +94,17 @@ pub fn metatable(ctx: Context) -> Table {
}),
);

let eq_fn = ctx.state.registry.stash(
&ctx,
AnyCallback::from_fn(&ctx, move |ctx, _fuel, mut stack| {
let (this, other): (AnyUserData, AnyUserData) = stack.consume(ctx)?;
let (this, other) = (
this.downcast_static::<&Schema>()?,
other.downcast_static::<&Schema>()?,
);
stack.replace(ctx, this.id() == other.id());
Ok(CallbackReturn::Return)
}),
);
let eq_fn = AnyCallback::from_fn(&ctx, move |ctx, _fuel, mut stack| {
let (this, other): (AnyUserData, AnyUserData) = stack.consume(ctx)?;
let (this, other) = (
this.downcast_static::<&Schema>()?,
other.downcast_static::<&Schema>()?,
);
stack.replace(ctx, this.id() == other.id());
Ok(CallbackReturn::Return)
});

metatable.set(ctx, "__eq", eq_fn).unwrap();
metatable
.set(
ctx,
Expand All @@ -116,7 +114,6 @@ pub fn metatable(ctx: Context) -> Table {
let this = this.downcast_static::<&Schema>()?;

match key.as_bytes() {
b"eq" => stack.replace(ctx, ctx.state.registry.fetch(&eq_fn)),
b"name" => {
stack.replace(
ctx,
Expand Down
Loading