lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


I made this a while back as a quick example.

But jgiors said why not just rely on sdl or whatever your game is using ?


#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
#include <unistd.h>

static int l_usleep(lua_State *L)
{
usleep( luaL_checkint(L,-1) );
return 0;
}

static int l_msleep(lua_State *L)
{
usleep( luaL_checkint(L,-1) * 1000 );
return 0;
}

static int l_sleep(lua_State *L)
{
sleep( luaL_checkint(L,-1) );
return 0;
}

int luaopen_sleep(lua_State *L)
{
lua_register( L, "usleep", l_usleep );
lua_register( L, "msleep", l_msleep );
lua_register( L, "sleep", l_sleep );
return 1;
}


On Wed, Oct 13, 2010 at 2:35 PM, Enrico Colombini <erix@erix.it> wrote:
On 13/10/2010 20.09, Henning Diedrich wrote:
I tried the following, with sockets being the best so far but it
appeared to hang sometimes when running in the background.

You could put a very short sleep inside Gabriel's timed loop. Even if the sleep wouldn't be interruptible, the loop would.
(it'd only make sense for relatively long sleep times because of sleep time granularity)

--
 Enrico