Guest User

Untitled

a guest
Nov 23rd, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.53 KB | None | 0 0
  1. int LuaShell::TimedCall(lua_State* L)
  2. {
  3.     luaL_argcheck(L, lua_type(L, 1) == LUA_TFUNCTION, 1, "setTimeout requires a function.");
  4.     double timeout = luaL_checknumber(L, 2);
  5.  
  6.     lua_State* globalL = lua_getstate(L);
  7.     RegValue v = lua_toregvalue(L, -1);
  8.     TimeManager::getSingleton().SetTimeout([globalL, v](double t)->double {
  9.         try
  10.         {
  11.             lua_pushregvalue(globalL, v);
  12.             return lua_tcall<double, double>(globalL, t);
  13.         }
  14.         catch (const std::exception& ex)
  15.         {
  16.             // log something.
  17.             return -1;
  18.         }
  19.     }, timeout);
  20.     return 0;
  21. }
Add Comment
Please, Sign In to add comment