Browse files

ctr.time() returns a negative value; updated documentation and sprite…

  • Loading branch information...
Reuh committed Apr 25, 2016
1 parent 2504fc9 commit f554f53a47d08ce79e0dfb153b48ae91180fc45c
Showing with 14 additions and 2 deletions.
  1. +1 −1 sdcard/3ds/ctruLua/libs/sprite.lua
  2. +13 −1 source/ctr.c
@@ -68,7 +68,7 @@ function, fsx, fsy)
animations = {},
currentAnimation = 0,
currentFrame = 1,
frameTimer = 0,
frameTimer = ctr.time(),

draw = draw,
addAnimation = addAnimation,
@@ -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 for this use.
For various reasons (see the C source), this will actually returns a negative value.
@function time
@treturn number milliseconds
-- 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;

0 comments on commit f554f53

Please sign in to comment.