ArtMOO
|
00001 #ifndef LUA_TASK_H 00002 #define LUA_TASK_H 00003 00004 #include "mooglobal.h" 00005 00006 #include <lua.hpp> 00007 00008 #include <QList> 00009 #include "task.h" 00010 00011 class Connection; 00012 class Verb; 00013 00014 class lua_task 00015 { 00016 public: 00017 static lua_task *luaGetTask( lua_State *L ); 00018 00019 static void luaSetTask( lua_State *L, lua_task *T ); 00020 00021 public: 00022 lua_task( ConnectionId pConnectionId, const Task &pTask ); 00023 00024 virtual ~lua_task( void ); 00025 00026 inline const Task &task( void ) const 00027 { 00028 return( mTasks.first() ); 00029 } 00030 00031 inline lua_State *L( void ) const 00032 { 00033 return( mL ); 00034 } 00035 00036 int execute( qint64 pTimeStamp ); 00037 00038 int eval( void ); 00039 00040 void taskPush( const Task &T ); 00041 void taskPop( void ); 00042 00043 int verbCall( ObjectId pObjectId, Verb *V, int pArgCnt = 0 ); 00044 int verbCall( Task &pTask, Verb *V, int pArgCnt ); 00045 00046 int throwError( mooError pError, const QString pMessage = "" ); 00047 00048 inline ConnectionId connectionid( void ) 00049 { 00050 return( mConnectionId ); 00051 } 00052 00053 inline qint64 timestamp( void ) const 00054 { 00055 return( mTimeStamp ); 00056 } 00057 00058 inline ObjectId programmer( void ) const 00059 { 00060 return( mTasks.first().programmer() ); 00061 } 00062 00063 inline void setProgrammer( ObjectId pObjectId ) 00064 { 00065 mTasks.first().setProgrammer( pObjectId ); 00066 } 00067 00068 private: 00069 static void initialise( void ); 00070 00071 static void luaRegisterState( lua_State *L ); 00072 00073 static int luaObject( lua_State *L ); 00074 static int luaVerb( lua_State *L ); 00075 static int luaArgs( lua_State *L ); 00076 static int luaArgStr( lua_State *L ); 00077 static int luaCaller( lua_State *L ); 00078 static int luaPlayer( lua_State *L ); 00079 static int luaHere( lua_State *L ); 00080 static int luaMe( lua_State *L ); 00081 static int luaTask( lua_State *L ); 00082 static int luaKill( lua_State *L ); 00083 static int luaDirectObject( lua_State *L ); 00084 static int luaDirectObjectString( lua_State *L ); 00085 static int luaIndirectObject( lua_State *L ); 00086 static int luaIndirectObjectString( lua_State *L ); 00087 00088 static int luaGetProgrammer( lua_State *L ); 00089 static int luaSetProgrammer( lua_State *L ); 00090 00091 static void luaHook( lua_State *L, lua_Debug *ar ); 00092 00093 int execute( void ); 00094 int executeLogin( void ); 00095 00096 int verbCallCode( Verb *V, int pArgCnt = 0 ); 00097 00098 static void *luaAlloc( void *ud, void *ptr, size_t osize, size_t nsize ); 00099 void *luaAlloc( void *ptr, size_t osize, size_t nsize ); 00100 00101 private: 00102 lua_State *mL; 00103 ConnectionId mConnectionId; 00104 QList<Task> mTasks; 00105 qint64 mTimeStamp; // when the current task was started 00106 size_t mMemUse; 00107 00108 static const luaL_Reg mLuaStatic[]; 00109 static const luaL_Reg mLuaGet[]; 00110 static const luaL_Reg mLuaSet[]; 00111 00112 friend class lua_moo; 00113 }; 00114 00115 #endif // LUA_TASK_H