From f554f53a47d08ce79e0dfb153b48ae91180fc45c Mon Sep 17 00:00:00 2001 From: Reuh Date: Mon, 25 Apr 2016 21:02:32 +0200 Subject: [PATCH] ctr.time() returns a negative value; updated documentation and sprite.lua --- sdcard/3ds/ctruLua/libs/sprite.lua | 2 +- source/ctr.c | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/sdcard/3ds/ctruLua/libs/sprite.lua b/sdcard/3ds/ctruLua/libs/sprite.lua index 621e4d8..7e82555 100644 --- a/sdcard/3ds/ctruLua/libs/sprite.lua +++ b/sdcard/3ds/ctruLua/libs/sprite.lua @@ -68,7 +68,7 @@ function mod.new(texture, fsx, fsy) animations = {}, currentAnimation = 0, currentFrame = 1, - frameTimer = 0, + frameTimer = ctr.time(), draw = draw, addAnimation = addAnimation, diff --git a/source/ctr.c b/source/ctr.c index c545a84..80d36f1 100644 --- a/source/ctr.c +++ b/source/ctr.c @@ -140,11 +140,23 @@ static int ctr_run(lua_State *L) { } /*** -Return the number of milliseconds since 1st Jan 1900 00:00. +Return the number of milliseconds spent since some point in time. +This can be used to measure a duration with milliseconds precision; however this can't be used to get the current time or date. +See Lua's os.date() for this use. +For various reasons (see the C source), this will actually returns a negative value. @function time @treturn number milliseconds +@usage +-- Measuring a duration: +local startTime = ctr.time() +-- do stuff +local duration = ctr.time() - startTime */ static int ctr_time(lua_State *L) { + // osGetTime actually returns the number of seconds elapsed since 1st Jan 1900 00:00. + // However, it returns a u64, we build Lua with 32bits numbers, and every number is signed in Lua, so this obvioulsy doesn't work + // and actually returns a negative value. It still works for durations however. Because having the date and time with millisecond-presion + // doesn't really seem useful and changing ctrµLua's API to work on 64bits numbers will take a long time, we choosed to keep this as-is. lua_pushinteger(L, osGetTime()); return 1;