added a way to loop through every table
This commit is contained in:
parent
c9a626cdab
commit
bd5ce01234
2 changed files with 26 additions and 3 deletions
|
@ -1,4 +1,4 @@
|
|||
use std::{collections::HashMap, io::{BufReader, Read, Write}, net::{self, TcpListener, TcpStream}, process, thread::sleep, time::Duration};
|
||||
use std::{collections::HashMap, io::{BufReader, Read, Write}, net::{self, TcpListener, TcpStream}, process, thread::sleep, time::Duration, vec};
|
||||
|
||||
use crate::{errors::{create_error, print_error, ErrorSubType, ErrorType}, virtualmachine::{DecompiledOperation, Machine, TableValue, VMMemory, VMMemoryBoolean, VMMemoryNativeFunction, VMMemoryNull, VMMemoryNumber, VMMemoryString, VMMemoryTable}};
|
||||
|
||||
|
@ -530,6 +530,24 @@ fn tabla_torol(machine: &mut Machine, op: &DecompiledOperation, args: Vec<VMMemo
|
|||
}
|
||||
return VMMemory::Table(VMMemoryTable { values: tbl.values.clone(), variable_id: 0 });
|
||||
}
|
||||
fn tabla_kulcsok(machine: &mut Machine, op: &DecompiledOperation, args: Vec<VMMemory>) -> VMMemory {
|
||||
arg_expect(&args, 0, "table", machine, op);
|
||||
let tbl = match &args[0] {
|
||||
VMMemory::Table(tbl) => tbl.clone(),
|
||||
_ => {
|
||||
error(String::from("Expected a table"), machine, op);
|
||||
return VMMemory::Null(VMMemoryNull { variable_id: 0 });
|
||||
}
|
||||
};
|
||||
let mut keys = VMMemoryTable {
|
||||
values: vec![],
|
||||
variable_id: 0,
|
||||
};
|
||||
for kv in &tbl.values {
|
||||
keys.values.push(TableValue { key: VMMemory::Number(VMMemoryNumber { value: keys.values.len() as i64, variable_id: 0 }), value: kv.key.clone() });
|
||||
}
|
||||
return VMMemory::Table(keys);
|
||||
}
|
||||
|
||||
pub fn generate() -> HashMap<String, VMMemory> {
|
||||
let mut mem: HashMap<String, VMMemory> = HashMap::new();
|
||||
|
@ -607,6 +625,10 @@ pub fn generate() -> HashMap<String, VMMemory> {
|
|||
TableValue {
|
||||
key: VMMemory::String(VMMemoryString { value: String::from("töröl"), variable_id: 0 }),
|
||||
value: VMMemory::NativeFunction(VMMemoryNativeFunction { func: tabla_torol, variable_id: 0 }),
|
||||
},
|
||||
TableValue {
|
||||
key: VMMemory::String(VMMemoryString { value: String::from("kulcsok"), variable_id: 0 }),
|
||||
value: VMMemory::NativeFunction(VMMemoryNativeFunction { func: tabla_kulcsok, variable_id: 0 }),
|
||||
}
|
||||
];
|
||||
mem.insert(String::from("tábla"), VMMemory::Table(VMMemoryTable { values: table, variable_id: 0 }));
|
||||
|
|
5
test.asl
5
test.asl
|
@ -1,5 +1,6 @@
|
|||
gethelj a = {1,2}
|
||||
gethelj a = {1,2,[szaft"test"szaft]=128}
|
||||
a = tábla.hozzáad(a, 1)
|
||||
ugass(a)
|
||||
a = tábla.töröl(a, 0)
|
||||
ugass(a)
|
||||
ugass(a)
|
||||
ugass(tábla.kulcsok(a))
|
Loading…
Add table
Add a link
Reference in a new issue