Модуль types

This commit is contained in:
Victor 2016-01-09 14:00:07 +02:00
parent 87637951a8
commit 556a0be4c2
2 changed files with 40 additions and 0 deletions

View File

@ -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))

View File

@ -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()));
}
}