Skip to content

Commit 8972020

Browse files
authored
Added 2 functions
1 parent 05fb7cf commit 8972020

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

Onion/SourceCode/ast/lib/Functions.cs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ static Functions()
3232
functions.Add("n", new ForN());
3333
functions.Add("not", new ForNot());
3434
functions.Add("cmd", new ForCmd());
35+
functions.Add("get_keyf", new ForGetKeyF());
36+
functions.Add("num_to_char", new ForIntToChar());
3537
}
3638

3739
public void getModule(string name)
@@ -400,7 +402,28 @@ public Value execute(Value[] args)
400402
{
401403
if (args.Length != 0) throw new Exception("Zero args expected");
402404
char key = Console.ReadKey(true).KeyChar;
403-
return new UserValue(key);
405+
return new StringValue(key.ToString());
406+
}
407+
}
408+
409+
public class ForGetKeyF : Function
410+
{
411+
private static NumberValue ZERO = new NumberValue(0);
412+
public Value execute(Value[] args)
413+
{
414+
if (args.Length != 0) throw new Exception("Zero args expected");
415+
int key = Console.ReadKey(true).KeyChar;
416+
return new NumberValue(key);
417+
}
418+
}
419+
420+
public class ForIntToChar : Function
421+
{
422+
private static NumberValue ZERO = new NumberValue(0);
423+
public Value execute(Value[] args)
424+
{
425+
if (args.Length != 1) throw new Exception("One arg expected");
426+
return new StringValue(args[0].asString());
404427
}
405428
}
406429

0 commit comments

Comments
 (0)