add settypeid
This commit is contained in:
parent
eb1335ade4
commit
fccce8b705
1 changed files with 21 additions and 6 deletions
|
@ -3,7 +3,6 @@ use std::{
|
|||
env::{args, vars},
|
||||
fs,
|
||||
io::{stdin, stdout, Write},
|
||||
mem,
|
||||
ops::{Add, Div, Mul, Rem, Sub},
|
||||
process::{self, Stdio},
|
||||
sync::Arc,
|
||||
|
@ -96,12 +95,27 @@ pub fn settype(stack: &mut Stack) -> OError {
|
|||
let o = stack.pop();
|
||||
let kind = runtime(|rt| rt.get_type_by_name(&s))
|
||||
.ok_or_else(|| stack.error(ErrorKind::TypeNotFound(s)))?;
|
||||
set_type_internal(&o, kind);
|
||||
stack.push(o);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn settypeid(stack: &mut Stack) -> OError {
|
||||
let Value::Int(i) = stack.pop().lock_ro().native.clone() else {
|
||||
return stack.err(ErrorKind::InvalidCall("settype".to_owned()));
|
||||
};
|
||||
let o = stack.pop();
|
||||
let kind = runtime(|rt| rt.get_type_by_id(i as u32))
|
||||
.ok_or_else(|| stack.error(ErrorKind::TypeNotFound(format!(";{i}"))))?;
|
||||
set_type_internal(&o, kind);
|
||||
stack.push(o);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn set_type_internal(o: &Arc<Mut<Object>>, kind: Arc<Mut<Type>>) {
|
||||
let mut obj = o.lock();
|
||||
kind.lock_ro().write_into(&mut obj);
|
||||
obj.kind = kind;
|
||||
mem::drop(obj);
|
||||
stack.push(o);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn gettype(stack: &mut Stack) -> OError {
|
||||
|
@ -1010,12 +1024,12 @@ pub fn properties(stack: &mut Stack) -> OError {
|
|||
let o = stack.pop();
|
||||
let o = o.lock_ro();
|
||||
let additional: Vec<AMObject> = vec![
|
||||
Value::Array(vec![";".to_owned().spl(), o.native.clone().spl()]).spl(),
|
||||
Value::Array(vec![
|
||||
":".to_owned().spl(),
|
||||
o.kind.lock_ro().get_name().spl(),
|
||||
])
|
||||
.spl(),
|
||||
Value::Array(vec![";".to_owned().spl(), o.native.clone().spl()]).spl(),
|
||||
];
|
||||
stack.push(
|
||||
Value::Array(
|
||||
|
@ -1072,7 +1086,7 @@ pub fn from_properties(stack: &mut Stack) -> OError {
|
|||
|
||||
pub fn register(r: &mut Stack, o: Arc<Frame>) {
|
||||
type Fn = fn(&mut Stack) -> OError;
|
||||
let fns: [(&str, Fn, u32); 64] = [
|
||||
let fns: [(&str, Fn, u32); 65] = [
|
||||
("pop", pop, 0),
|
||||
("dup", dup, 2),
|
||||
("dup2", dup2, 3),
|
||||
|
@ -1083,6 +1097,7 @@ pub fn register(r: &mut Stack, o: Arc<Frame>) {
|
|||
("gettype", gettype, 1),
|
||||
("gettypeid", gettypeid, 1),
|
||||
("settype", settype, 1),
|
||||
("settypeid", settypeid, 1),
|
||||
("banew", barray_new, 1),
|
||||
("anew", array_new, 1),
|
||||
("array-len", array_len, 1),
|
||||
|
|
Loading…
Add table
Reference in a new issue