Implementation of TypeID in Lua
1#include <sys/time.h>
2
3#include "lua.h"
4#include "lauxlib.h"
5
6static int time(lua_State *L) {
7 struct timeval time;
8 gettimeofday(&time, NULL);
9 lua_Number milliseconds = (time.tv_sec * 1000) + (time.tv_usec / 1000);
10 lua_pushnumber(L, milliseconds);
11
12 return 1;
13}
14
15int luaopen_millitime(lua_State *L) {
16 static const luaL_Reg mylib [] = {
17 {"time", time},
18 {NULL, NULL}
19 };
20
21 lua_newtable(L);
22#if LUA_VERSION_NUM > 501
23 luaL_setfuncs(L, mylib, 0);
24#else
25 luaL_register(L, NULL, mylib);
26#endif
27 return 1;
28}