-
-
Notifications
You must be signed in to change notification settings - Fork 165
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
Why does setTimeout and setInterval can't be transpiled to Lua? #1467
Comments
I think the reason is, that until now, no one asked for it. Most applications/games offer a custom API that can achieve similar behavior. |
Generally you need two things to implement a timer:
I am not aware of a way to get these with just bare Lua. Generally every Lua target environment I have seen has its own way of doing these things, hence we cannot just provide a generic implementation. Even if we had an implementation, we would probably still need you to somehow provide some code to do these two things. At that point it is probably simpler to just use the environment-specific timing capabilities with some declarations. I am not against providing a lualib polyfill for these, but it needs to work for all (or most of) our targets, otherwise we are better off just deferring this to the user. I'm open to suggestions for ways to do this. |
Just checked, there is indeed no good way to get the current time. Luas So I don't think adding support for setInterval and setTimeout will be possible. |
One way would be to go full abstract/agnostic, so no matter what Lua environment is being used, a programmer would provide these requirements/arguments to the lualib. Expose a method to set it up before being able to use it? |
Yeah, some way of integrating this would be great, personally, I'm running a Lua runtime that does support this, which makes it a bit annoying that I cant use it. |
If you have to provide some binding code to make setTimeout work with your own timers, what is the benefit over just using that timer declaration directly? In fact you could just add your own setTimeout implementation to your environment to be used by the default declarations: function setTimeout(handler: () => void, timeout: number) {
// code calling your environment timer here
} (you will need to make sure this lua file is loaded as part of the global scope ofc |
I've just noticed that setTimeout and setInterval can't be transpiled to Lua with TypescriptToLua but there are some solutions for this in Lua such as timers (wait), coroutines, etc... then why it can't transpile setTimeout and setInterval functions?
The text was updated successfully, but these errors were encountered: