mirror of
https://github.com/aNNiMON/Own-Programming-Language-Tutorial.git
synced 2024-09-20 00:34:20 +03:00
Модуль types
This commit is contained in:
parent
87637951a8
commit
556a0be4c2
16
program.own
16
program.own
@ -111,3 +111,19 @@ for (v : arr1 << arr2) print "" + v + ", "
|
|||||||
print "\n"
|
print "\n"
|
||||||
for v : [1,2,3,4,5,6,7,8,9] print "" + v + ", "
|
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))
|
24
src/com/annimon/ownlang/lib/modules/types.java
Normal file
24
src/com/annimon/ownlang/lib/modules/types.java
Normal 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()));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user