Search code examples
timelua

Lua - Current time in milliseconds


Is there a common way to get the current time in or with milliseconds?

There is os.time(), but it only provides full seconds.


Solution

  • In standard C lua, no. You will have to settle for seconds, unless you are willing to modify the lua interpreter yourself to have os.time use the resolution you want. That may be unacceptable, however, if you are writing code for other people to run on their own and not something like a web application where you have full control of the environment.

    Edit: another option is to write your own small DLL in C that extends lua with a new function that would give you the values you want, and require that dll be distributed with your code to whomever is going to be using it.