diff options
Diffstat (limited to 'lib/BLua.cc')
-rw-r--r-- | lib/BLua.cc | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/lib/BLua.cc b/lib/BLua.cc index f7f8d53..76cd443 100644 --- a/lib/BLua.cc +++ b/lib/BLua.cc @@ -88,6 +88,8 @@ class LuaStatics : public Base { static int getenv(lua_State *); static int setenv(lua_State *); static int unsetenv(lua_State *); + + static int sleep(lua_State *); static int globalindex(lua_State *); @@ -361,7 +363,7 @@ int LuaStatics::unsetenv(lua_State * _L) { int n = L->gettop(); /* number of arguments */ if (n != 1) { - L->error("Incorrect arguments to function `setenv'"); + L->error("Incorrect arguments to function `unsetenv'"); } ::unsetenv(L->tostring(1).to_charp()); @@ -369,6 +371,26 @@ int LuaStatics::unsetenv(lua_State * _L) { return 0; } +int LuaStatics::sleep(lua_State * _L) { + Lua * L = Lua::find(_L); + int t; + + int n = L->gettop(); /* number of arguments */ + if ((n != 1) || !L->isnumber(1)) { + L->error("Incorrect arguments to function `sleep'"); + } + + t = L->tonumber(1); + +#ifdef _WIN32 + ::Sleep(t); +#else + ::usleep(t * 1000); +#endif + + return 0; +} + int LuaStatics::print(lua_State * _L) { Lua * L = Lua::find(_L); @@ -556,6 +578,9 @@ void Lua::open_base() { push("unsetenv"); push(LuaStatics::unsetenv); settable(LUA_GLOBALSINDEX); + push("sleep"); + push(LuaStatics::sleep); + settable(LUA_GLOBALSINDEX); } void Lua::open_table() { |