Skip to content

Commit

Permalink
Version 1.2.4
Browse files Browse the repository at this point in the history
  • Loading branch information
EmDeeTee committed Mar 11, 2023
1 parent 54b7777 commit 743db92
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 21 deletions.
2 changes: 2 additions & 0 deletions Changelog.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
Changelog for 1.2.4
- Added 'Fetch(url)',
- Added 'Sleep(timeMs)',
- Added `ConvertToDouble()`,
- Fixed a bug that allowed for assingment of variables in structs that weren't defined as members,
- Fixed a crash if you wanted to assign a value to a nonexistant struct,
Expand Down
25 changes: 20 additions & 5 deletions IterkoczeScript/Functions/Basic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,32 @@ public static class Basic {
Console.ForegroundColor = ConsoleColor.Blue;
break;
default:
new RuntimeError("The colour wasn't defined!");
_ = new RuntimeError("The colour wasn't defined!");
break;

}
if (args[0] != null)
Console.WriteLine(args[0]);
if (args[0] != null) {
try {
var x = args[0] as Task<object?>;
Console.WriteLine(x.Result);

}
catch {
Console.WriteLine(args[0]);
}
}
Console.ForegroundColor = oldColour;
}
else {
if (args[0] != null)
Console.WriteLine(args[0]);
if (args[0] != null) {
try {
var x = args[0] as Task<object?>;
Console.WriteLine(x.Result);

} catch {
Console.WriteLine(args[0]);
}
}
}
return null;
}
Expand Down
21 changes: 21 additions & 0 deletions IterkoczeScript/Functions/Network.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using System.Net.NetworkInformation;
using IterkoczeScript.Interpreter;
using System.Net;
using Newtonsoft.Json.Linq;
using System;

namespace IterkoczeScript.Functions;

Expand Down Expand Up @@ -61,4 +63,23 @@ public static class Network {
}
return null;
}
public async static Task<object?> Fetch(object?[] args) {
if (args.Length != 1)
_ = new RuntimeError("Function \"Fetch\" expects at 1 argument. URL");

string url = args[0].ToString();

if (!Uri.IsWellFormedUriString(url, UriKind.RelativeOrAbsolute)) {
IError err = new ErrorMalformattedURL();
err.SetError();
return err;
}

using (HttpClient client = new HttpClient()) {
HttpResponseMessage response = await client.GetAsync(url);
response.EnsureSuccessStatusCode();
string responseBody = await response.Content.ReadAsStringAsync();
return JObject.Parse(responseBody);
}
}
}
14 changes: 13 additions & 1 deletion IterkoczeScript/Functions/Utility.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using IterkoczeScript.Errors;
using Antlr4.Runtime.Misc;
using IterkoczeScript.Errors;
using IterkoczeScript.Interpreter;
using System.Diagnostics;

Expand Down Expand Up @@ -75,4 +76,15 @@ public static class Utility {
public static object? Linux(object?[] args) {
return OperatingSystem.IsLinux();
}
public static object? Sleep(object?[] args) {
if (args.Length != 1)
_ = new RuntimeError("Function \"Sleep\" expects 1 argument.");

if (!int.TryParse(args[0].ToString(), out int time)) {
_ = new RuntimeError($"{args[0]} in not a number. Sleep(timeMs)");
}

Thread.Sleep(time);
return null;
}
}
4 changes: 3 additions & 1 deletion IterkoczeScript/Interpreter/IterkoczeScriptVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public class IterkoczeScriptVisitor : IterkoczeScriptBaseVisitor<object?> {
STANDARD_FUNCTIONS["ClearRuntimeTimer"] = new Func<object?[], object?>(Functions.Utility.ClearRuntimeTimer);
STANDARD_FUNCTIONS["Execute"] = new Func<object?[], object?>(Functions.Utility.Execute);
STANDARD_FUNCTIONS["Linux"] = new Func<object?[], object?>(Functions.Utility.Linux);
STANDARD_FUNCTIONS["Sleep"] = new Func<object?[], object?>(Functions.Utility.Sleep);


// IO
STANDARD_FUNCTIONS["WriteFile"] = new Func<object?[], object?>(IO.FileWrite);
Expand Down Expand Up @@ -72,6 +74,7 @@ public class IterkoczeScriptVisitor : IterkoczeScriptBaseVisitor<object?> {
// NETWORK
STANDARD_FUNCTIONS["IsServerUp"] = new Func<object?[], object?>(Network.IsServerUp);
STANDARD_FUNCTIONS["Download"] = new Func<object?[], object?>(Network.Download);
STANDARD_FUNCTIONS["Fetch"] = new Func<object?[], object?>(Network.Fetch);

// "SECURITY" LULW
STANDARD_FUNCTIONS["SHA1"] = new Func<object?[], object?>(Security.SHA1);
Expand Down Expand Up @@ -647,7 +650,6 @@ public class IterkoczeScriptVisitor : IterkoczeScriptBaseVisitor<object?> {
"!=" => Compare.IsNotEqual(left, right),
">" => Compare.GreaterThan(left, right),
"<" => Compare.LessThan(left, right),
//">=" => IsEqual(left, right),
"<=" => Compare.LessOrEqual(left, right),
_ => throw new NotImplementedException()
};
Expand Down
13 changes: 0 additions & 13 deletions IterkoczeScript/WorkingDir/Main.is
Original file line number Diff line number Diff line change
@@ -1,13 +0,0 @@
option = Read("add or sub?: ");
number1 = ConvertToInt(Read("Number: "));
number2 = ConvertToInt(Read("Number: "));

perhaps {
Write(number1 + number2);
} if (option == "add");
perhaps {
Write(number1 - number2);
} if (option == "sub");
otherwise {
Write("Wrong operation!");
}
1 change: 0 additions & 1 deletion TODO.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
Finally fix the give not stopping bug
add turer as optional true

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

0 comments on commit 743db92

Please sign in to comment.