在编写代码的时候,我们经常需要打印时间戳,或者是在开启多线程之前获取一下当前系统的cpu数目。在java中,我们可以直接调用system下面的接口即可。所以Obotcha仿造java,在lang目录下也有一个system类,目前它提供了一些常用功能的接口:
static long int currentTimeMillis();
static void exit(int);
static int availableProcessors();
static int onlineProcessors();
static String executeForResult(String cmd);
static void execute(String cmd);
调用的这些静态函数的时候可能需要注意一下,由于Obotcha声明class的时候做了转义,所有如果按照C++的标准写法class::interface()的话,是无法找到对应接口的。Obotcha中有一个st的宏,就是用来调用class的static成员变量或者函数的。
具体的用法如下:
long current = st(System)::currentTimeMillis();
后续Obotcha会在system中添加更多的公共功能接口。方便开发者直接调用。
Obotcha github:
https://github.com/wangsun1983/Obotcha/blob/master/lang/System.cpp