Lua取毫秒的C 扩展

2015-12-14 0 630
Lua取毫秒的C 扩展
#include <stdio.h>
#include <sys/time.h>
#include <time.h>
#include <lua.h>
#include <lauxlib.h>

//微秒
static int getmicrosecond(lua_State *L) {
    struct timeval tv;
    gettimeofday(&tv,NULL);
    long microsecond = tv.tv_sec*1000000+tv.tv_usec;
    lua_pushnumber(L, microsecond);
    return 1;
}

//毫秒
static int getmillisecond(lua_State *L) {
    struct timeval tv;
    gettimeofday(&tv,NULL);
    long millisecond = (tv.tv_sec*1000000+tv.tv_usec)/1000;
    lua_pushnumber(L, millisecond);
    
    return 1;
}


int luaopen_usertime(lua_State *L) {
  luaL_checkversion(L);

  luaL_Reg l[] = {
    {"getmillisecond", getmillisecond},
    {"getmicrosecond", getmicrosecond},
    { NULL, NULL },
  };

  luaL_newlib(L, l);
  return 1;
}

遇见资源网 lua Lua取毫秒的C 扩展 http://www.ox520.com/14719.html

Lua取毫秒的C 扩展
上一篇:

已经没有上一篇了!

Java 编码例子
下一篇: Java 编码例子
常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务