mirror of
https://github.com/Dummi26/mers.git
synced 2025-03-10 14:13:52 +01:00
add childproc_write_* functions
This commit is contained in:
parent
5d752c9969
commit
6fdfba82a0
@ -1,6 +1,6 @@
|
|||||||
use std::{
|
use std::{
|
||||||
fmt::Display,
|
fmt::Display,
|
||||||
io::{BufRead, BufReader, Read},
|
io::{BufRead, BufReader, Read, Write},
|
||||||
process::{ChildStderr, ChildStdin, ChildStdout, Command, Stdio},
|
process::{ChildStderr, ChildStdin, ChildStdout, Command, Stdio},
|
||||||
sync::{Arc, Mutex},
|
sync::{Arc, Mutex},
|
||||||
};
|
};
|
||||||
@ -179,6 +179,64 @@ impl Config {
|
|||||||
inner_statements: None,
|
inner_statements: None,
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
.add_var(
|
||||||
|
"childproc_write_bytes".to_string(),
|
||||||
|
Data::new(data::function::Function {
|
||||||
|
info: Arc::new(program::run::Info::neverused()),
|
||||||
|
info_check: Arc::new(Mutex::new( CheckInfo::neverused())),
|
||||||
|
out: Arc::new(|a, _i| {
|
||||||
|
if a.types.iter().all(|a| a.as_any().downcast_ref::<data::tuple::TupleT>().is_some_and(|t| t.0.len() == 2 && t.0[0].is_included_in(&ChildProcessT) && t.0[1].iterable().is_some_and(|i| i.is_included_in(&data::int::IntT)))) {
|
||||||
|
Ok(Type::new(data::bool::BoolT))
|
||||||
|
} else {
|
||||||
|
return Err(format!("childproc_write_bytes called on non-`(ChildProcess, Iter<Int>)` type {a}").into());
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
run: Arc::new(|a, _i| {
|
||||||
|
let a = a.get();
|
||||||
|
let tuple = a.as_any().downcast_ref::<data::tuple::Tuple>().unwrap();
|
||||||
|
let child = tuple.0[0].get();
|
||||||
|
let bytes = tuple.0[1].get();
|
||||||
|
let child = child.as_any().downcast_ref::<ChildProcess>().unwrap();
|
||||||
|
let mut child = child.0.lock().unwrap();
|
||||||
|
let buf = bytes.iterable().unwrap().map(|v| v.get().as_any().downcast_ref::<data::int::Int>().unwrap().0.max(0).min(255) as u8).collect::<Vec<_>>();
|
||||||
|
if child.1.write_all(&buf).is_ok() {
|
||||||
|
Data::new(data::bool::Bool(true))
|
||||||
|
} else {
|
||||||
|
Data::new(data::bool::Bool(false))
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
inner_statements: None,
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
.add_var(
|
||||||
|
"childproc_write_string".to_string(),
|
||||||
|
Data::new(data::function::Function {
|
||||||
|
info: Arc::new(program::run::Info::neverused()),
|
||||||
|
info_check: Arc::new(Mutex::new( CheckInfo::neverused())),
|
||||||
|
out: Arc::new(|a, _i| {
|
||||||
|
if a.is_included_in(&data::tuple::TupleT(vec![Type::new(ChildProcessT), Type::new(data::string::StringT)])) {
|
||||||
|
Ok(Type::new(data::bool::BoolT))
|
||||||
|
} else {
|
||||||
|
return Err(format!("childproc_write_string called on non-`(ChildProcess, String)` type {a}").into());
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
run: Arc::new(|a, _i| {
|
||||||
|
let a = a.get();
|
||||||
|
let tuple = a.as_any().downcast_ref::<data::tuple::Tuple>().unwrap();
|
||||||
|
let child = tuple.0[0].get();
|
||||||
|
let string = tuple.0[1].get();
|
||||||
|
let child = child.as_any().downcast_ref::<ChildProcess>().unwrap();
|
||||||
|
let mut child = child.0.lock().unwrap();
|
||||||
|
let buf = string.as_any().downcast_ref::<data::string::String>().unwrap().0.as_bytes();
|
||||||
|
if child.1.write_all(buf).is_ok() {
|
||||||
|
Data::new(data::bool::Bool(true))
|
||||||
|
} else {
|
||||||
|
Data::new(data::bool::Bool(false))
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
inner_statements: None,
|
||||||
|
}),
|
||||||
|
)
|
||||||
.add_var(
|
.add_var(
|
||||||
"childproc_read_byte".to_string(),
|
"childproc_read_byte".to_string(),
|
||||||
Data::new(data::function::Function {
|
Data::new(data::function::Function {
|
||||||
|
Loading…
Reference in New Issue
Block a user