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
|
@ -119,6 +119,7 @@ Példa: `kábel.halgass`
|
||||||
|Név|Leírás|Használat|Példa|
|
|Név|Leírás|Használat|Példa|
|
||||||
|---|---|---|---|
|
|---|---|---|---|
|
||||||
|halgass|Hallgat egy porton.|`halgass(host: string, port: number): halgató`|`halgass(szaft"0.0.0.0"szaft,1010)`|
|
|halgass|Hallgat egy porton.|`halgass(host: string, port: number): halgató`|`halgass(szaft"0.0.0.0"szaft,1010)`|
|
||||||
|
|kapcsolódj|Rákapcsolódik egy célra.|`kapcsolódj(target: string): kapcsolat`|`kapcsolódj(szaft"example.com:80"szaft)`|
|
||||||
|
|
||||||
:::warning
|
:::warning
|
||||||
|
|
||||||
|
|
|
@ -119,6 +119,7 @@ Példa: `kábel.halgass`
|
||||||
|Név|Leírás|Használat|Példa|
|
|Név|Leírás|Használat|Példa|
|
||||||
|---|---|---|---|
|
|---|---|---|---|
|
||||||
|halgass|Hallgat egy porton.|`halgass(host: string, port: number): halgató`|`halgass(szaft"0.0.0.0"szaft,1010)`|
|
|halgass|Hallgat egy porton.|`halgass(host: string, port: number): halgató`|`halgass(szaft"0.0.0.0"szaft,1010)`|
|
||||||
|
|kapcsolódj|Rákapcsolódik egy célra.|`kapcsolódj(target: string): kapcsolat`|`kapcsolódj(szaft"example.com:80"szaft)`|
|
||||||
|
|
||||||
:::warning
|
:::warning
|
||||||
|
|
||||||
|
|
BIN
extension/astrolang-extension-1.0.2.vsix
Normal file
BIN
extension/astrolang-extension-1.0.2.vsix
Normal file
Binary file not shown.
|
@ -66,6 +66,7 @@ vscode.languages.registerCompletionItemProvider('astrolang', {
|
||||||
"vége",
|
"vége",
|
||||||
|
|
||||||
"halgass",
|
"halgass",
|
||||||
|
"kapcsolódj",
|
||||||
"kérés",
|
"kérés",
|
||||||
"írj",
|
"írj",
|
||||||
"olvass",
|
"olvass",
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
"name": "astrolang-extension",
|
"name": "astrolang-extension",
|
||||||
"displayName": "Astro Lang",
|
"displayName": "Astro Lang",
|
||||||
"icon": "asl.png",
|
"icon": "asl.png",
|
||||||
"version": "1.0.1",
|
"version": "1.0.2",
|
||||||
"description": "The extension for Astro Lang",
|
"description": "The extension for Astro Lang",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"author": "Afonya",
|
"author": "Afonya",
|
||||||
|
|
|
@ -436,12 +436,12 @@ fn kabel_irj(machine: &mut Machine, op: &DecompiledOperation, args: Vec<VMMemory
|
||||||
if stream.is_none() {
|
if stream.is_none() {
|
||||||
error(String::from("Stream is not a TcpStream"), machine, op);
|
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] {
|
let write = match &args[1] {
|
||||||
VMMemory::String(s) => s.value.clone(),
|
VMMemory::String(s) => s.value.clone(),
|
||||||
_ => String::new()
|
_ => String::new()
|
||||||
};
|
};
|
||||||
match listener.write_all(write.as_bytes()) {
|
match stream.write_all(write.as_bytes()) {
|
||||||
Ok(_) => {},
|
Ok(_) => {},
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
error(format!("Failed to write to stream: {}", e), machine, op);
|
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 });
|
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 {
|
fn kabel_halgass(machine: &mut Machine, op: &DecompiledOperation, args: Vec<VMMemory>) -> VMMemory {
|
||||||
arg_expect(&args, 0, "string", machine, op);
|
arg_expect(&args, 0, "string", machine, op);
|
||||||
arg_expect(&args, 1, "number", machine, op);
|
arg_expect(&args, 1, "number", machine, op);
|
||||||
|
@ -1161,6 +1195,10 @@ pub fn generate() -> HashMap<String, VMMemory> {
|
||||||
TableValue {
|
TableValue {
|
||||||
key: VMMemory::String(VMMemoryString { value: String::from("halgass"), variable_id: 0 }),
|
key: VMMemory::String(VMMemoryString { value: String::from("halgass"), variable_id: 0 }),
|
||||||
value: VMMemory::NativeFunction(VMMemoryNativeFunction { func: kabel_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 }));
|
mem.insert(String::from("kábel"), VMMemory::Table(VMMemoryTable { values: kabel, variable_id: 0 }));
|
||||||
|
|
|
@ -10,7 +10,7 @@ mod virtualmachine;
|
||||||
mod errors;
|
mod errors;
|
||||||
mod decompiler;
|
mod decompiler;
|
||||||
|
|
||||||
const CLIVER: [u8; 3] = [1,0,0];
|
const CLIVER: [u8; 3] = [1,0,1];
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
struct Context {
|
struct Context {
|
||||||
|
|
19
test.asl
19
test.asl
|
@ -1,11 +1,8 @@
|
||||||
lőcsve test() {
|
gethelj con = kábel.kapcsolódj(szaft"example.com:80"szaft)
|
||||||
lőcsve toast() {
|
con.írj(con, szaft"GET / HTTP/1.1
|
||||||
ugass(2)
|
User-Agent: Astro Lang
|
||||||
}
|
Host: example.com
|
||||||
toast()
|
|
||||||
ugass(1)
|
"szaft)
|
||||||
}
|
ugass(con.olvass(con, 5120))
|
||||||
gethelj k = krumpli.létrehoz(test)
|
con.zár(con)
|
||||||
ugass(krumpli.státusz(k))
|
|
||||||
krumpli.folytat(k)
|
|
||||||
ugass(krumpli.státusz(k))
|
|
Loading…
Add table
Add a link
Reference in a new issue