Skip to content

Commit 556a0be

Browse files
committed
Модуль types
1 parent 8763795 commit 556a0be

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

program.own

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,19 @@ for (v : arr1 << arr2) print "" + v + ", "
111111
print "\n"
112112
for v : [1,2,3,4,5,6,7,8,9] print "" + v + ", "
113113

114+
use "types"
115+
print "\n"
116+
print typeof(1)
117+
print "\n"
118+
print typeof("1")
119+
print "\n"
120+
print typeof(arr1)
121+
print "\n"
122+
print typeof({})
123+
print "\n"
124+
print typeof(add)
125+
126+
print "\n"
127+
print typeof(number("1"))
128+
print "\n"
129+
print typeof(string(1))
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.annimon.ownlang.lib.modules;
2+
3+
import com.annimon.ownlang.lib.*;
4+
5+
/**
6+
*
7+
* @author aNNiMON
8+
*/
9+
public final class types implements Module {
10+
11+
@Override
12+
public void init() {
13+
Variables.set("OBJECT", new NumberValue(Types.OBJECT));
14+
Variables.set("NUMBER", new NumberValue(Types.NUMBER));
15+
Variables.set("STRING", new NumberValue(Types.STRING));
16+
Variables.set("ARRAY", new NumberValue(Types.ARRAY));
17+
Variables.set("MAP", new NumberValue(Types.MAP));
18+
Variables.set("FUNCTION", new NumberValue(Types.FUNCTION));
19+
20+
Functions.set("typeof", args -> new NumberValue(args[0].type()));
21+
Functions.set("string", args -> new StringValue(args[0].asString()));
22+
Functions.set("number", args -> new NumberValue(args[0].asNumber()));
23+
}
24+
}

0 commit comments

Comments
 (0)