| /* All the functions in this file runs with aLua stack, and can |
| * return with a longjmp. All of these function must be launched |
| * in an environment able to catch a longjmp, otherwise a |
| * critical error can be raised. |
| */ |
| #include <lauxlib.h> |
| #include <lua.h> |
| #include <lualib.h> |
| |
| #include <common/time.h> |
| |
| /* This function return the current date at epoch format in milliseconds. */ |
| int hlua_now(lua_State *L) |
| { |
| lua_newtable(L); |
| lua_pushstring(L, "sec"); |
| lua_pushinteger(L, now.tv_sec); |
| lua_rawset(L, -3); |
| lua_pushstring(L, "usec"); |
| lua_pushinteger(L, now.tv_usec); |
| lua_rawset(L, -3); |
| return 1; |
| } |
| |
| static void hlua_array_add_fcn(lua_State *L, const char *name, |
| int (*function)(lua_State *L)) |
| { |
| lua_pushstring(L, name); |
| lua_pushcclosure(L, function, 0); |
| lua_rawset(L, -3); |
| } |
| |
| int hlua_fcn_reg_core_fcn(lua_State *L) |
| { |
| hlua_array_add_fcn(L, "now", hlua_now); |
| return 1; |
| } |