File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed
src/main/java/com/annimon/ownlang/modules/std Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change
1
+ package com .annimon .ownlang .modules .std ;
2
+
3
+ import com .annimon .ownlang .lib .Arguments ;
4
+ import com .annimon .ownlang .lib .NumberValue ;
5
+ import com .annimon .ownlang .lib .StringValue ;
6
+ import com .annimon .ownlang .lib .Types ;
7
+ import com .annimon .ownlang .lib .Value ;
8
+
9
+ public final class NumberFunctions {
10
+
11
+ public static Value toHexString (Value ... args ) {
12
+ Arguments .check (1 , args .length );
13
+ long value ;
14
+ if (args [0 ].type () == Types .NUMBER ) {
15
+ value = ((NumberValue ) args [0 ]).asLong ();
16
+ } else {
17
+ value = (long ) args [0 ].asNumber ();
18
+ }
19
+ return new StringValue (Long .toHexString (value ));
20
+ }
21
+ }
Original file line number Diff line number Diff line change @@ -27,6 +27,9 @@ public void init() {
27
27
Functions .set ("sync" , new std_sync ());
28
28
Functions .set ("try" , new std_try ());
29
29
30
+ // Numbers
31
+ Functions .set ("toHexString" , NumberFunctions ::toHexString );
32
+
30
33
// String
31
34
Functions .set ("sprintf" , new std_sprintf ());
32
35
Functions .set ("split" , new std_split ());
You can’t perform that action at this time.
0 commit comments