Thread: While Loop and Delay

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    4

    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...

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >but the program becomes incredibly slow
    >every time i run this to call the function
    Almost as if you were somehow pausing the program?
    My best code is written with the delete key.

  3. #3
    Registered User
    Join Date
    Feb 2008
    Posts
    4
    yea, i wonder why the not responding thing and the program crashes, i guess because its paused :P

  4. #4
    Registered User
    Join Date
    Sep 2007
    Posts
    1,012
    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.

  5. #5
    uint64_t...think positive xuftugulus's Avatar
    Join Date
    Feb 2008
    Location
    Pacem
    Posts
    355
    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.
    Code:
    ...
        goto johny_walker_red_label;
    johny_walker_blue_label: exit(-149$);
    johny_walker_red_label : exit( -22$);
    A typical example of ...cheap programming practices.

  6. #6
    Registered User
    Join Date
    Feb 2008
    Posts
    4
    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++
    Last edited by hmd; 02-25-2008 at 04:19 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need advice to provide accurate time delay in C
    By kenkoh in forum C Programming
    Replies: 14
    Last Post: 04-30-2008, 11:13 AM
  2. Looking for a way to store listbox data
    By Welder in forum C Programming
    Replies: 20
    Last Post: 11-01-2007, 11:48 PM
  3. temperature sensors
    By danko in forum C Programming
    Replies: 22
    Last Post: 07-10-2007, 07:26 PM
  4. Delay
    By CanadianOutlaw in forum C++ Programming
    Replies: 4
    Last Post: 09-13-2001, 06:28 AM
  5. Delay A While Loop
    By SonicWave in forum C++ Programming
    Replies: 4
    Last Post: 09-09-2001, 10:29 PM