Browse Source

feat: 新增time模块

time模块含time函数, 可以获得时间戳

link #7
SongZihuan 4 years ago
parent
commit
56eb1a6cf5
3 changed files with 21 additions and 1 deletions
  1. 1 1
      vmcore/ofunc/clib/lib.h
  2. 1 0
      vmcore/ofunc/clib/manager.c
  3. 19 0
      vmcore/ofunc/clib/sys_time.c

+ 1 - 1
vmcore/ofunc/clib/lib.h

@@ -2,5 +2,5 @@
 #define VIRTUALMATH_LIB_H
 #include "__ofunc.h"
 void registeredSysLib(R_FUNC);
-
+void registeredTimeLib(R_FUNC);
 #endif //VIRTUALMATH_LIB_H

+ 1 - 0
vmcore/ofunc/clib/manager.c

@@ -5,6 +5,7 @@ static struct InFo{
     char *name;
     Registered reg;
 } ManagerInFo[] = {{"sys", registeredSysLib},
+                   {"time", registeredTimeLib},
                    {NULL, NULL}};
 
 bool checkCLib(char *file) {

+ 19 - 0
vmcore/ofunc/clib/sys_time.c

@@ -0,0 +1,19 @@
+#include "lib.h"
+
+static ResultType vm_selfunCore(O_FUNC){
+    time_t t;
+    if (arg != NULL) {
+        setResultError(E_ArgumentException, MANY_ARG, LINEFILE, true, CNEXT_NT);
+        return R_error;
+    }
+
+    time(&t);
+    makeIntValue(t, LINEFILE, CNEXT_NT);
+    return result->type;
+}
+
+void registeredTimeLib(R_FUNC){
+    NameFunc tmp[] = {{L"time", vm_selfunCore, fp_no_, .var=nfv_notpush},
+                      {NULL, NULL}};
+    iterBaseNameFunc(tmp, belong, CFUNC_CORE(var_list));
+}