From 5a6c25887ad86c7c4c59f867e5181092d2ac06fb Mon Sep 17 00:00:00 2001 From: KimLS Date: Sat, 22 Feb 2014 15:26:18 -0800 Subject: [PATCH] Export of eq.clock(), os.clock() isn't a good option on unix --- zone/lua_general.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/zone/lua_general.cpp b/zone/lua_general.cpp index 1c22865c9..7b275ea67 100644 --- a/zone/lua_general.cpp +++ b/zone/lua_general.cpp @@ -16,6 +16,7 @@ #include "QuestParserCollection.h" #include "questmgr.h" #include "QGlobals.h" +#include "../common/timer.h" struct Events { }; struct Factions { }; @@ -1064,6 +1065,13 @@ void lua_clear_npctype_cache(int npctype_id) { quest_manager.ClearNPCTypeCache(npctype_id); } +double lua_clock() { + timeval read_time; + gettimeofday(&read_time, nullptr); + uint32 t = read_time.tv_sec * 1000 + read_time.tv_usec / 1000; + return static_cast(t) / 1000.0; +} + luabind::scope lua_register_general() { return luabind::namespace_("eq") [ @@ -1231,7 +1239,8 @@ luabind::scope lua_register_general() { luabind::def("clear_opcode", &lua_clear_opcode), luabind::def("enable_recipe", &lua_enable_recipe), luabind::def("disable_recipe", &lua_disable_recipe), - luabind::def("clear_npctype_cache", &lua_clear_npctype_cache) + luabind::def("clear_npctype_cache", &lua_clear_npctype_cache), + luabind::def("clock", &lua_clock) ]; }