removed queue.push
This commit is contained in:
+4
-25
@@ -43,9 +43,9 @@
|
||||
//!
|
||||
//! ## Queue API
|
||||
//!
|
||||
//! `Queue.length()`, `Queue.clear()`, `Queue.peek()`, `Queue.pop()`, `Queue.push(map)`
|
||||
//! `Queue.length()`, `Queue.clear()`, `Queue.peek()`, `Queue.pop()`
|
||||
|
||||
use crate::action::{action_to_map, rhai_action_module, Action, ScrollLine, MOVE_COST};
|
||||
use crate::action::{action_to_map, Action, ScrollLine, MOVE_COST};
|
||||
use crate::board::Board;
|
||||
use crate::log::LogLine;
|
||||
use crate::map_file::{color_to_hex, parse_color};
|
||||
@@ -173,10 +173,9 @@ impl ScriptHost {
|
||||
let errors: ErrorSink = Rc::new(RefCell::new(Vec::new()));
|
||||
|
||||
let mut engine = Engine::new();
|
||||
engine.register_static_module("Action", rhai_action_module().into());
|
||||
register_read_api(&mut engine, board_cell, &board_queue, &errors);
|
||||
register_write_api(&mut engine, &queues);
|
||||
register_queue_api(&mut engine, &errors);
|
||||
register_queue_api(&mut engine);
|
||||
register_me_type(&mut engine);
|
||||
register_object_info_type(&mut engine);
|
||||
register_glyph_type(&mut engine);
|
||||
@@ -717,7 +716,7 @@ fn register_write_api(engine: &mut Engine, queues: &QueueMap) {
|
||||
|
||||
// ── Queue API ─────────────────────────────────────────────────────────────────
|
||||
|
||||
fn register_queue_api(engine: &mut Engine, errors: &ErrorSink) {
|
||||
fn register_queue_api(engine: &mut Engine) {
|
||||
engine.register_type_with_name::<ObjQueue>("Queue");
|
||||
engine.register_fn("length", |q: &mut ObjQueue| q.borrow().len() as i64);
|
||||
engine.register_fn("clear", |q: &mut ObjQueue| q.borrow_mut().clear());
|
||||
@@ -738,26 +737,6 @@ fn register_queue_api(engine: &mut Engine, errors: &ErrorSink) {
|
||||
.map(|a| Dynamic::from(action_to_map(a)))
|
||||
.unwrap_or(Dynamic::UNIT)
|
||||
});
|
||||
|
||||
// push(map): parse the map into an Action and enqueue; log an error on failure.
|
||||
let errs = errors.clone();
|
||||
// We need the queues map here to route push to the right object's queue.
|
||||
// Since push() is called on the Queue handle directly, we use that handle.
|
||||
engine.register_fn("push", move |q: &mut ObjQueue, map: Dynamic| {
|
||||
let rhai_map = match map.try_cast::<rhai::Map>() {
|
||||
Some(m) => m,
|
||||
None => {
|
||||
errs.borrow_mut().push(LogLine::error(
|
||||
"Queue.push: argument must be an Action map".to_string(),
|
||||
));
|
||||
return;
|
||||
}
|
||||
};
|
||||
match Action::try_from(rhai_map) {
|
||||
Ok(action) => q.borrow_mut().push_back(action),
|
||||
Err(msg) => errs.borrow_mut().push(LogLine::error(format!("Queue.push: {msg}"))),
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// ── Scope construction ────────────────────────────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user