Search code examples
timelualuaj

Luaj os.time() return milliseconds


os.time() in Luaj returns time in milliseconds, but according to lua documentation, it should return time in seconds.

  1. Is this a bug in Luaj?
  2. And Can you suggest a workaround that will work with Luaj(for java) and real Lua(c/c++)? because i have to use the same lua source for both applications.(cant simply divide it with 1000, as they both have return different time scale)

example in my lua file:

local start = os.time()
while(true) do
    print(os.time() - start)
end

in c++ , i received output:

1
1
1
...(1 seconds passed)
2
2
2

in java (using Luaj), i got:

1
...(terminate in eclipse as fast as my finger can)
659
659
659
659

fyi, i try this on windows


Solution

  • Lua manual about os.time():

    The returned value is a number, whose meaning depends on your system. In POSIX, Windows, and some other systems, this number counts the number of seconds since some given start time (the "epoch"). In other systems, the meaning is not specified, and the number returned by time can be used only as an argument to os.date and os.difftime.

    So, any Lua implementation could freely change the meaning of os.time() value.