Add from_value variable constructor
This commit is contained in:
parent
417b3b53b4
commit
5f48d20f2a
|
@ -1,6 +1,6 @@
|
|||
//! Number constants.
|
||||
|
||||
use std::{cell::RefCell, collections::HashMap, rc::Rc};
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::variables::{Value, Variable};
|
||||
|
||||
|
@ -32,13 +32,7 @@ pub fn ablescript_consts() -> HashMap<String, Variable> {
|
|||
("OCTOTHORPE", Str("#".to_owned())), // It's an octothorpe
|
||||
("ANSWER", Int(ANSWER)),
|
||||
] {
|
||||
map.insert(
|
||||
(*name).to_owned(),
|
||||
Variable {
|
||||
melo: false,
|
||||
value: Rc::new(RefCell::new(value.to_owned())),
|
||||
},
|
||||
);
|
||||
map.insert((*name).to_owned(), Variable::from_value(value.to_owned()));
|
||||
}
|
||||
|
||||
map
|
||||
|
|
|
@ -263,8 +263,9 @@ impl Value {
|
|||
)
|
||||
.into_abool(),
|
||||
Functio::Able { params, body } => {
|
||||
let str_to_isize =
|
||||
|x: String| -> isize { x.as_bytes().into_iter().map(|x| *x as isize).sum() };
|
||||
let str_to_isize = |x: String| -> isize {
|
||||
x.as_bytes().into_iter().map(|x| *x as isize).sum()
|
||||
};
|
||||
|
||||
let params: isize = params.into_iter().map(str_to_isize).sum();
|
||||
let body: isize = body
|
||||
|
@ -1006,3 +1007,12 @@ pub struct Variable {
|
|||
// pass-by-reference is used, therefore we use Rc here.
|
||||
pub value: Rc<RefCell<Value>>,
|
||||
}
|
||||
|
||||
impl Variable {
|
||||
pub fn from_value(value: Value) -> Self {
|
||||
Self {
|
||||
melo: false,
|
||||
value: Rc::new(RefCell::new(value)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue