Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
SAPI: Move core.get_us_time() to Util module
  • Loading branch information
kwolekr committed Oct 26, 2015
1 parent 5f342aa commit 306b067
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 12 deletions.
2 changes: 2 additions & 0 deletions doc/menu_lua_api.txt
Expand Up @@ -191,6 +191,8 @@ core.create_world(worldname, gameid)
core.delete_world(index)

Helpers:
core.get_us_time()
^ returns time with microsecond precision

This comment has been minimized.

Copy link
@PilzAdam

PilzAdam Oct 26, 2015

Contributor

Which time? Time since epoch, or some arbitrary point? Does it vary between restarts? Is it affected by changing the system time?

This comment has been minimized.

Copy link
@kwolekr

kwolekr Oct 27, 2015

Author Contributor

Dunno, just copied the description from lua_api.txt.

core.gettext(string) -> string
^ look up the translation of a string in the gettext message catalog
fgettext_ne(string, ...)
Expand Down
9 changes: 0 additions & 9 deletions src/script/lua_api/l_env.cpp
Expand Up @@ -938,14 +938,6 @@ int ModApiEnvMod::l_forceload_free_block(lua_State *L)
return 0;
}

// get_us_time()
int ModApiEnvMod::l_get_us_time(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
lua_pushnumber(L, porting::getTimeUs());
return 1;
}

void ModApiEnvMod::Initialize(lua_State *L, int top)
{
API_FCT(set_node);
Expand Down Expand Up @@ -987,5 +979,4 @@ void ModApiEnvMod::Initialize(lua_State *L, int top)
API_FCT(transforming_liquid_add);
API_FCT(forceload_block);
API_FCT(forceload_free_block);
API_FCT(get_us_time);
}
3 changes: 0 additions & 3 deletions src/script/lua_api/l_env.h
Expand Up @@ -168,9 +168,6 @@ class ModApiEnvMod : public ModApiBase {
// stops forceloading a position
static int l_forceload_free_block(lua_State *L);

// get us precision time
static int l_get_us_time(lua_State *L);

public:
static void Initialize(lua_State *L, int top);
};
Expand Down
12 changes: 12 additions & 0 deletions src/script/lua_api/l_util.cpp
Expand Up @@ -65,6 +65,14 @@ int ModApiUtil::l_log(lua_State *L)
return 0;
}

// get_us_time()
int ModApiUtil::l_get_us_time(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
lua_pushnumber(L, porting::getTimeUs());
return 1;
}

#define CHECK_SECURE_SETTING(L, name) \
if (name.compare(0, 7, "secure.") == 0) {\
lua_pushliteral(L, "Attempt to set secure setting.");\
Expand Down Expand Up @@ -368,6 +376,8 @@ void ModApiUtil::Initialize(lua_State *L, int top)
{
API_FCT(log);

API_FCT(get_us_time);

API_FCT(setting_set);
API_FCT(setting_get);
API_FCT(setting_setbool);
Expand Down Expand Up @@ -399,6 +409,8 @@ void ModApiUtil::InitializeAsync(AsyncEngine& engine)
{
ASYNC_API_FCT(log);

ASYNC_API_FCT(get_us_time);

//ASYNC_API_FCT(setting_set);
ASYNC_API_FCT(setting_get);
//ASYNC_API_FCT(setting_setbool);
Expand Down
3 changes: 3 additions & 0 deletions src/script/lua_api/l_util.h
Expand Up @@ -41,6 +41,9 @@ class ModApiUtil : public ModApiBase {
// The two-argument version accept a log level: error, action, info, or verbose.
static int l_log(lua_State *L);

// get us precision time
static int l_get_us_time(lua_State *L);

// setting_set(name, value)
static int l_setting_set(lua_State *L);

Expand Down

0 comments on commit 306b067

Please sign in to comment.