lua: use base::Chrono for os.clock() (which has more precision)

This commit is contained in:
David Capello 2018-09-03 13:29:10 -03:00
parent bc092b4512
commit c5a5a7858c

View File

@ -13,6 +13,7 @@
#include "app/app.h"
#include "app/console.h"
#include "app/script/luacpp.h"
#include "base/chrono.h"
#include "base/fstream_path.h"
#include "doc/color_mode.h"
@ -24,6 +25,9 @@ namespace script {
namespace {
// High precision clock.
base::Chrono luaClock;
int print(lua_State* L)
{
std::string output;
@ -52,6 +56,12 @@ int print(lua_State* L)
return 0;
}
int os_clock(lua_State* L)
{
lua_pushnumber(L, luaClock.elapsed());
return 1;
}
int unsupported(lua_State* L)
{
// debug.getinfo(1, "n").name
@ -105,6 +115,8 @@ Engine::Engine()
lua_pushcfunction(L, unsupported);
lua_setfield(L, -2, name);
}
lua_pushcfunction(L, os_clock);
lua_setfield(L, -2, "clock");
lua_pop(L, 1);
// Generic code used by metatables