diff --git a/program.own b/program.own index cdf16cb..0cda45e 100644 --- a/program.own +++ b/program.own @@ -111,3 +111,19 @@ for (v : arr1 << arr2) print "" + v + ", " print "\n" for v : [1,2,3,4,5,6,7,8,9] print "" + v + ", " +use "types" +print "\n" +print typeof(1) +print "\n" +print typeof("1") +print "\n" +print typeof(arr1) +print "\n" +print typeof({}) +print "\n" +print typeof(add) + +print "\n" +print typeof(number("1")) +print "\n" +print typeof(string(1)) \ No newline at end of file diff --git a/src/com/annimon/ownlang/lib/modules/types.java b/src/com/annimon/ownlang/lib/modules/types.java new file mode 100644 index 0000000..e82d2a2 --- /dev/null +++ b/src/com/annimon/ownlang/lib/modules/types.java @@ -0,0 +1,24 @@ +package com.annimon.ownlang.lib.modules; + +import com.annimon.ownlang.lib.*; + +/** + * + * @author aNNiMON + */ +public final class types implements Module { + + @Override + public void init() { + Variables.set("OBJECT", new NumberValue(Types.OBJECT)); + Variables.set("NUMBER", new NumberValue(Types.NUMBER)); + Variables.set("STRING", new NumberValue(Types.STRING)); + Variables.set("ARRAY", new NumberValue(Types.ARRAY)); + Variables.set("MAP", new NumberValue(Types.MAP)); + Variables.set("FUNCTION", new NumberValue(Types.FUNCTION)); + + Functions.set("typeof", args -> new NumberValue(args[0].type())); + Functions.set("string", args -> new StringValue(args[0].asString())); + Functions.set("number", args -> new NumberValue(args[0].asNumber())); + } +}