-
While Loop and Delay
I am doing this LUA project which includes a C dll. I need it to call a function every 50 milliseconds, i know how to call this function but the program becomes incredibly slow every time i run this to call the function:
Code:
While (true) {
// Call Lua Function
sleep(50);
}
and i have searched the internet and found no other delay method, i can use a timer but it doesn't work with lua (if you want a it to call a lua command, u need a lua_State *L sent to you, or other it won't call it). Help...
-
>but the program becomes incredibly slow
>every time i run this to call the function
Almost as if you were somehow pausing the program? ;)
-
yea, i wonder why the not responding thing and the program crashes, i guess because its paused :P
-
I don't know what operating system you're on, but if it's unix-like, sleep()'s argument is seconds, not milliseconds. You might be interested in usleep(), the argument of which specifies microseconds. If it's another OS, this doesn't (necessarily) apply.
-
I don't know much about LUA but i know it binds tightly to C, and if sleep(50) is biased to C sleep(50) then it will stop for 50 seconds, at least that's what the sleep reference says. Is there a usleep() for LUA? It sleeps for microseconds up to 1.000.000 if i recall in C, maybe it is available for you too.
-
Windows, its milliseconds since i did a echo thing in lua and there comes lots of messages, about 5 because then it crashes. Please give me another way to delay the loop lol
EDIT: Also LUA doesn't Contain Sleep command lol... I have to use C functions which i build with VC++