- Add predefined variables

- Add `mod` function
- Improve function calling syntax
This commit is contained in:
Stone_Red
2022-01-13 13:39:02 +01:00
parent ea5bbda2c7
commit 4bef308ff2
5 changed files with 155 additions and 32 deletions
@@ -0,0 +1,50 @@
using System;
using YesNt.Interpreter.Attributes;
using YesNt.Interpreter.Enums;
using YesNt.Interpreter.Utilities;
namespace YesNt.Interpreter.Statements
{
internal class PredifinedVariableStatements : StatementRuntimeInformation
{
private readonly Random random = new Random();
[Statement("%tim", SearchMode.Contains, SpaceAround.End, ConsoleColor.Blue, KeepStatementInArgs = true, Priority = Priority.Highest)]
public void GetUnixTimestamp(string args)
{
args += " ";
while (args.Contains("%tim "))
{
args = args.ReplaceFirstOccurrence("%tim ", $"{DateTimeOffset.Now.ToUnixTimeSeconds()}");
}
RuntimeInfo.CurrentLine = args.TrimEnd();
}
[Statement("%pi", SearchMode.Contains, SpaceAround.End, ConsoleColor.Blue, KeepStatementInArgs = true, Priority = Priority.Highest)]
public void GetPi(string args)
{
args += " ";
args = args.Replace("%pi ", $"{Math.PI} ");
RuntimeInfo.CurrentLine = args.TrimEnd();
}
[Statement("%rnd", SearchMode.Contains, SpaceAround.End, ConsoleColor.Blue, KeepStatementInArgs = true, Priority = Priority.Highest)]
public void GetRandom(string args)
{
args += " ";
while (args.Contains("%rnd "))
{
args = args.ReplaceFirstOccurrence("%rnd ", $"{random.Next() % 2} ");
}
RuntimeInfo.CurrentLine = args.TrimEnd();
}
}
}