/**********************************************************\ | | | xxtea.c | | | | XXTEA encryption algorithm library for Lua. | | | | Encryption Algorithm Authors: | | David J. Wheeler | | Roger M. Needham | | | | Code Authors: Chen fei | | Ma Bingyao | | LastModified: Feb 7, 2016 | | | \**********************************************************/ #include "lua.h" #include "lauxlib.h" #include static int vsec(lua_State *L) { struct timeval t_val; gettimeofday(&t_val, NULL); lua_pushnumber(L, t_val.tv_sec); lua_pushnumber(L, t_val.tv_usec); return 2; } static int nsec(lua_State *L) { struct timespec tp; clock_gettime(0, &tp); lua_pushnumber(L, tp.tv_sec); lua_pushnumber(L, tp.tv_nsec); return 2; } // static int nsec(lua_State *L) // { // struct timespec t_val; // gettimeofday(&t_val, NULL); // lua_pushnumber(L, t_val.tv_nsec); // return 1; // } static const luaL_Reg hightimer[] = { {"vsec", vsec}, {"nsec", nsec}, {0, 0} }; LUALIB_API int luaopen_hightimer(lua_State * L) { #if LUA_VERSION_NUM >= 502 // LUA 5.2 or above lua_newtable(L); luaL_setfuncs(L, hightimer, 0); #else luaL_register(L, "hightimer", hightimer); #endif return 1; }