File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -26,6 +26,16 @@ void register_string_natives(VM* vm);
2626void register_convert_natives (VM * vm );
2727void register_system_natives (VM * vm );
2828
29+ // Exposed natives
30+ extern Value native_clock (int argCount , Value * args );
31+
32+ static Value native_len (int argCount , Value * args ) {
33+ if (argCount < 1 ) return NUMBER_VAL (0 );
34+ if (IS_STRING (args [0 ])) return NUMBER_VAL ((double )AS_STRING (args [0 ])-> length );
35+ // TODO: List/Map support
36+ return NUMBER_VAL (0 );
37+ }
38+
2939static void registerModule (VM * vm , const char * name , ObjModule * module ) {
3040 ObjString * nameObj = copyString (name , (int )strlen (name ));
3141 push (vm , OBJ_VAL (nameObj ));
@@ -177,4 +187,8 @@ void registerStdLib(VM* vm) {
177187 tableSet (& vm -> globals , stdName , OBJ_VAL (stdMod ));
178188 pop (vm ); // stdMod
179189 pop (vm ); // stdName
190+
191+ // Register simple globals for convenience
192+ defineNative (vm , "clock" , native_clock );
193+ defineNative (vm , "len" , native_len );
180194}
Original file line number Diff line number Diff line change @@ -40,7 +40,7 @@ static Value native_now(int argCount, Value* args) {
4040}
4141
4242// clock() -> Number (CPU time in seconds)
43- static Value native_clock (int argCount , Value * args ) {
43+ Value native_clock (int argCount , Value * args ) {
4444 (void )argCount ; (void )args ;
4545 return NUMBER_VAL ((double )clock () / CLOCKS_PER_SEC );
4646}
You can’t perform that action at this time.
0 commit comments