added ag::sleep()

git-svn-id: svn://anubis/anaglym/trunk@22 99a6e188-d820-4881-8870-2d33a10e2619
This commit is contained in:
Josh Holtrop 2009-09-20 01:32:27 +00:00
parent 6bb601355b
commit 8817201a27
2 changed files with 21 additions and 0 deletions

20
ag.cc
View File

@ -3,6 +3,7 @@
#include "ag.h" #include "ag.h"
#include "Video.h" #include "Video.h"
#include "wfobj/WFObj.hh" #include "wfobj/WFObj.hh"
#include <unistd.h> /* usleep() */
#include <lua.hpp> #include <lua.hpp>
#include <iostream> #include <iostream>
#include <string> #include <string>
@ -18,6 +19,7 @@ namespace ag
{ "loadModel", loadModel }, { "loadModel", loadModel },
{ "videoStart", videoStart }, { "videoStart", videoStart },
{ "videoStop", videoStop }, { "videoStop", videoStop },
{ "sleep", sleep },
{ NULL, NULL } { NULL, NULL }
}; };
luaL_register(L, "ag", functions); luaL_register(L, "ag", functions);
@ -115,10 +117,28 @@ namespace ag
int videoStart(lua_State * L) int videoStart(lua_State * L)
{ {
g_video->start(); g_video->start();
return 0;
} }
int videoStop(lua_State * L) int videoStop(lua_State * L)
{ {
g_video->stop(); g_video->stop();
return 0;
}
int sleep(lua_State * L)
{
int argc = lua_gettop(L);
if (argc == 1)
{
if (lua_type(L, -1) == LUA_TNUMBER)
{
double seconds = lua_tonumber(L, -1);
usleep((useconds_t) (seconds * 1000000));
}
}
return 0;
} }
} }

1
ag.h
View File

@ -12,6 +12,7 @@ namespace ag
int loadModel(lua_State * L); int loadModel(lua_State * L);
int videoStart(lua_State * L); int videoStart(lua_State * L);
int videoStop(lua_State * L); int videoStop(lua_State * L);
int sleep(lua_State * L);
} }
#endif #endif