Skip to content

Commit 743db92

Browse files
committed
Version 1.2.4
1 parent 54b7777 commit 743db92

File tree

7 files changed

+59
-21
lines changed

7 files changed

+59
-21
lines changed

Changelog.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
Changelog for 1.2.4
2+
- Added 'Fetch(url)',
3+
- Added 'Sleep(timeMs)',
24
- Added `ConvertToDouble()`,
35
- Fixed a bug that allowed for assingment of variables in structs that weren't defined as members,
46
- Fixed a crash if you wanted to assign a value to a nonexistant struct,

IterkoczeScript/Functions/Basic.cs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,32 @@ public static class Basic {
2222
Console.ForegroundColor = ConsoleColor.Blue;
2323
break;
2424
default:
25-
new RuntimeError("The colour wasn't defined!");
25+
_ = new RuntimeError("The colour wasn't defined!");
2626
break;
2727

2828
}
29-
if (args[0] != null)
30-
Console.WriteLine(args[0]);
29+
if (args[0] != null) {
30+
try {
31+
var x = args[0] as Task<object?>;
32+
Console.WriteLine(x.Result);
33+
34+
}
35+
catch {
36+
Console.WriteLine(args[0]);
37+
}
38+
}
3139
Console.ForegroundColor = oldColour;
3240
}
3341
else {
34-
if (args[0] != null)
35-
Console.WriteLine(args[0]);
42+
if (args[0] != null) {
43+
try {
44+
var x = args[0] as Task<object?>;
45+
Console.WriteLine(x.Result);
46+
47+
} catch {
48+
Console.WriteLine(args[0]);
49+
}
50+
}
3651
}
3752
return null;
3853
}

IterkoczeScript/Functions/Network.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
using System.Net.NetworkInformation;
33
using IterkoczeScript.Interpreter;
44
using System.Net;
5+
using Newtonsoft.Json.Linq;
6+
using System;
57

68
namespace IterkoczeScript.Functions;
79

@@ -61,4 +63,23 @@ public static class Network {
6163
}
6264
return null;
6365
}
66+
public async static Task<object?> Fetch(object?[] args) {
67+
if (args.Length != 1)
68+
_ = new RuntimeError("Function \"Fetch\" expects at 1 argument. URL");
69+
70+
string url = args[0].ToString();
71+
72+
if (!Uri.IsWellFormedUriString(url, UriKind.RelativeOrAbsolute)) {
73+
IError err = new ErrorMalformattedURL();
74+
err.SetError();
75+
return err;
76+
}
77+
78+
using (HttpClient client = new HttpClient()) {
79+
HttpResponseMessage response = await client.GetAsync(url);
80+
response.EnsureSuccessStatusCode();
81+
string responseBody = await response.Content.ReadAsStringAsync();
82+
return JObject.Parse(responseBody);
83+
}
84+
}
6485
}

IterkoczeScript/Functions/Utility.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using IterkoczeScript.Errors;
1+
using Antlr4.Runtime.Misc;
2+
using IterkoczeScript.Errors;
23
using IterkoczeScript.Interpreter;
34
using System.Diagnostics;
45

@@ -75,4 +76,15 @@ public static class Utility {
7576
public static object? Linux(object?[] args) {
7677
return OperatingSystem.IsLinux();
7778
}
79+
public static object? Sleep(object?[] args) {
80+
if (args.Length != 1)
81+
_ = new RuntimeError("Function \"Sleep\" expects 1 argument.");
82+
83+
if (!int.TryParse(args[0].ToString(), out int time)) {
84+
_ = new RuntimeError($"{args[0]} in not a number. Sleep(timeMs)");
85+
}
86+
87+
Thread.Sleep(time);
88+
return null;
89+
}
7890
}

IterkoczeScript/Interpreter/IterkoczeScriptVisitor.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ public IterkoczeScriptVisitor() {
3737
STANDARD_FUNCTIONS["ClearRuntimeTimer"] = new Func<object?[], object?>(Functions.Utility.ClearRuntimeTimer);
3838
STANDARD_FUNCTIONS["Execute"] = new Func<object?[], object?>(Functions.Utility.Execute);
3939
STANDARD_FUNCTIONS["Linux"] = new Func<object?[], object?>(Functions.Utility.Linux);
40+
STANDARD_FUNCTIONS["Sleep"] = new Func<object?[], object?>(Functions.Utility.Sleep);
41+
4042

4143
// IO
4244
STANDARD_FUNCTIONS["WriteFile"] = new Func<object?[], object?>(IO.FileWrite);
@@ -72,6 +74,7 @@ public IterkoczeScriptVisitor() {
7274
// NETWORK
7375
STANDARD_FUNCTIONS["IsServerUp"] = new Func<object?[], object?>(Network.IsServerUp);
7476
STANDARD_FUNCTIONS["Download"] = new Func<object?[], object?>(Network.Download);
77+
STANDARD_FUNCTIONS["Fetch"] = new Func<object?[], object?>(Network.Fetch);
7578

7679
// "SECURITY" LULW
7780
STANDARD_FUNCTIONS["SHA1"] = new Func<object?[], object?>(Security.SHA1);
@@ -647,7 +650,6 @@ public override object VisitArgumentAssingmentExp([NotNull] IterkoczeScriptParse
647650
"!=" => Compare.IsNotEqual(left, right),
648651
">" => Compare.GreaterThan(left, right),
649652
"<" => Compare.LessThan(left, right),
650-
//">=" => IsEqual(left, right),
651653
"<=" => Compare.LessOrEqual(left, right),
652654
_ => throw new NotImplementedException()
653655
};

IterkoczeScript/WorkingDir/Main.is

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +0,0 @@
1-
option = Read("add or sub?: ");
2-
number1 = ConvertToInt(Read("Number: "));
3-
number2 = ConvertToInt(Read("Number: "));
4-
5-
perhaps {
6-
Write(number1 + number2);
7-
} if (option == "add");
8-
perhaps {
9-
Write(number1 - number2);
10-
} if (option == "sub");
11-
otherwise {
12-
Write("Wrong operation!");
13-
}

TODO.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
Finally fix the give not stopping bug
2-
add turer as optional true
32

43
Don't forget to set the version in the CLI!

0 commit comments

Comments
 (0)