added a way to create a network connection
This commit is contained in:
parent
cb93fa917a
commit
f234dc1564
8 changed files with 53 additions and 15 deletions
|
@ -436,12 +436,12 @@ fn kabel_irj(machine: &mut Machine, op: &DecompiledOperation, args: Vec<VMMemory
|
|||
if stream.is_none() {
|
||||
error(String::from("Stream is not a TcpStream"), machine, op);
|
||||
}
|
||||
let mut listener = stream.unwrap();
|
||||
let mut stream = stream.unwrap();
|
||||
let write = match &args[1] {
|
||||
VMMemory::String(s) => s.value.clone(),
|
||||
_ => String::new()
|
||||
};
|
||||
match listener.write_all(write.as_bytes()) {
|
||||
match stream.write_all(write.as_bytes()) {
|
||||
Ok(_) => {},
|
||||
Err(e) => {
|
||||
error(format!("Failed to write to stream: {}", e), machine, op);
|
||||
|
@ -540,6 +540,40 @@ fn kabel_keres(machine: &mut Machine, op: &DecompiledOperation, args: Vec<VMMemo
|
|||
}
|
||||
return VMMemory::Null(VMMemoryNull { variable_id: 0 });
|
||||
}
|
||||
fn kabel_kapcsolodj(machine: &mut Machine, op: &DecompiledOperation, args: Vec<VMMemory>) -> VMMemory {
|
||||
arg_expect(&args, 0, "string", machine, op);
|
||||
let str = match &args[0] {
|
||||
VMMemory::String(s) => s.value.clone(),
|
||||
_ => String::new()
|
||||
};
|
||||
let stream = match TcpStream::connect(&str) {
|
||||
Ok(s) => s,
|
||||
Err(err) => {
|
||||
error(format!("Failed to connect to {}: {}", str, err), machine, op);
|
||||
return VMMemory::Null(VMMemoryNull { variable_id: 0 });
|
||||
}
|
||||
};
|
||||
machine.storage.push(Box::new(stream));
|
||||
let ret_table: Vec<TableValue> = vec![
|
||||
TableValue {
|
||||
key: VMMemory::String(VMMemoryString { value: String::from("olvass"), variable_id: 0 }),
|
||||
value: VMMemory::NativeFunction(VMMemoryNativeFunction { func: kabel_olvass, variable_id: 0 }),
|
||||
},
|
||||
TableValue {
|
||||
key: VMMemory::String(VMMemoryString { value: String::from("írj"), variable_id: 0 }),
|
||||
value: VMMemory::NativeFunction(VMMemoryNativeFunction { func: kabel_irj, variable_id: 0 }),
|
||||
},
|
||||
TableValue {
|
||||
key: VMMemory::String(VMMemoryString { value: String::from("zár"), variable_id: 0 }),
|
||||
value: VMMemory::NativeFunction(VMMemoryNativeFunction { func: kabel_zar, variable_id: 0 }),
|
||||
},
|
||||
TableValue {
|
||||
key: VMMemory::String(VMMemoryString { value: String::from("id"), variable_id: 0 }),
|
||||
value: VMMemory::Number(VMMemoryNumber { value: (machine.storage.len()-1) as f64, variable_id: 0 }),
|
||||
}
|
||||
];
|
||||
return VMMemory::Table(VMMemoryTable { values: ret_table, variable_id: 0 });
|
||||
}
|
||||
fn kabel_halgass(machine: &mut Machine, op: &DecompiledOperation, args: Vec<VMMemory>) -> VMMemory {
|
||||
arg_expect(&args, 0, "string", machine, op);
|
||||
arg_expect(&args, 1, "number", machine, op);
|
||||
|
@ -1161,6 +1195,10 @@ pub fn generate() -> HashMap<String, VMMemory> {
|
|||
TableValue {
|
||||
key: VMMemory::String(VMMemoryString { value: String::from("halgass"), variable_id: 0 }),
|
||||
value: VMMemory::NativeFunction(VMMemoryNativeFunction { func: kabel_halgass, variable_id: 0 }),
|
||||
},
|
||||
TableValue {
|
||||
key: VMMemory::String(VMMemoryString { value: String::from("kapcsolódj"), variable_id: 0 }),
|
||||
value: VMMemory::NativeFunction(VMMemoryNativeFunction { func: kabel_kapcsolodj, variable_id: 0 }),
|
||||
}
|
||||
];
|
||||
mem.insert(String::from("kábel"), VMMemory::Table(VMMemoryTable { values: kabel, variable_id: 0 }));
|
||||
|
|
|
@ -10,7 +10,7 @@ mod virtualmachine;
|
|||
mod errors;
|
||||
mod decompiler;
|
||||
|
||||
const CLIVER: [u8; 3] = [1,0,0];
|
||||
const CLIVER: [u8; 3] = [1,0,1];
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
struct Context {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue