Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grabbing current system time from lua? #42

Closed
zacharycarter opened this issue Dec 15, 2014 · 4 comments
Closed

Grabbing current system time from lua? #42

zacharycarter opened this issue Dec 15, 2014 · 4 comments

Comments

@zacharycarter
Copy link

So I don't think there's a lua binding to grab the current system time (please correct me if I'm mistaken), right now I think there is only the binding for grabbing the last frame's delta time - but I think this would be a nice to have.

I can add the binding if you think the enhancement is worth the effort. It would give me more insight into how the whole lua interop works.

Thanks,

  • Zach
@dbartolini
Copy link
Collaborator

You can use standard lua stuff: http://www.lua.org/pil/22.1.html
Is there anything particular you would like to have that is not covered by that?

@zacharycarter
Copy link
Author

I read those but I was concerned (and quite probably an invalid concern) about the precision of the time that the lua calls would be returning. Right now my goal is to grab the current system time so I can use it to adjust a shaders alpha blending using it. I'll give it a shot using the lua date / time stuff and see if I can't get it working. If I end up needing a more precise system time I'll reopen this.

@zacharycarter
Copy link
Author

Essentially what I'm looking to get is - clock()/CLOCKS_PER_SEC

@zacharycarter
Copy link
Author

os.clock is what I was looking for :

The os.clock function returns the number of seconds of CPU time for the program. Its typical use is to benchmark a piece of code:

local x = os.clock()
local s = 0
for i=1,100000 do s = s + i end
print(string.format("elapsed time: %.2f\n", os.clock() - x))

http://www.lua.org/pil/22.1.html - just for future reference / in case I forget in the future

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants