ArtMOO
|
00001 #ifndef FUNC_H 00002 #define FUNC_H 00003 00004 #include <QString> 00005 #include <QDataStream> 00006 #include <QStringList> 00007 00008 #include <lua.hpp> 00009 00010 #include "mooglobal.h" 00011 00012 class Func 00013 { 00014 public: 00015 virtual void save( QDataStream &pData ) const; 00016 virtual void load( QDataStream &pData ); 00017 00018 void initialise(); 00019 00020 int compile( void ); 00021 00022 typedef enum Permissions 00023 { 00024 READ = ( 1 << 0 ), 00025 WRITE = ( 1 << 1 ), 00026 EXECUTE = ( 1 << 2 ) 00027 } Permissions; 00028 00029 int lua_pushverb( lua_State *L ); 00030 00031 void setPermissions( quint16 pPerms ); 00032 quint16 permissions( void ); 00033 00034 inline ObjectId object( void ) const 00035 { 00036 return( mObject ); 00037 } 00038 00039 inline ObjectId owner( void ) const 00040 { 00041 return( mOwner ); 00042 } 00043 00044 inline bool read( void ) const 00045 { 00046 return( mRead ); 00047 } 00048 00049 inline bool write( void ) const 00050 { 00051 return( mWrite ); 00052 } 00053 00054 inline bool execute( void ) const 00055 { 00056 return( mExecute ); 00057 } 00058 00059 inline const QString &script( void ) const 00060 { 00061 return( mScript ); 00062 } 00063 00064 inline const QByteArray &compiled( void ) const 00065 { 00066 return( mCompiled ); 00067 } 00068 00069 inline bool dirty( void ) const 00070 { 00071 return( mDirty ); 00072 } 00073 00074 inline void setObject( ObjectId pObject ) 00075 { 00076 mObject = pObject; 00077 } 00078 00079 inline void setOwner( ObjectId pOwner ) 00080 { 00081 mOwner = pOwner; 00082 } 00083 00084 inline void setRead( bool pRead ) 00085 { 00086 mRead = pRead; 00087 } 00088 00089 inline void setWrite( bool pWrite ) 00090 { 00091 mWrite = pWrite; 00092 } 00093 00094 inline void setExecute( bool pExecute ) 00095 { 00096 mExecute = pExecute; 00097 } 00098 00099 inline void setScript( const QString &pScript ) 00100 { 00101 mScript = pScript; 00102 mDirty = true; 00103 } 00104 00105 private: 00106 static int writerStatic( lua_State *L, const void* p, size_t sz, void* ud ); 00107 int writer( lua_State *L, const void* p, size_t sz ); 00108 00109 static const char *readerStatic( lua_State *L, void *data, size_t *size ); 00110 const char *reader( lua_State *L, size_t *size ); 00111 00112 private: 00113 ObjectId mObject; // The object this func is attached to 00114 ObjectId mOwner; 00115 bool mRead; // lets non-owners see the program for a verb 00116 bool mWrite; // lets them change that program 00117 bool mExecute; // whether or not the verb can be invoked from within a MOO program (as opposed to from the command line, like the `put' verb on containers) 00118 QString mScript; 00119 QByteArray mCompiled; 00120 bool mDirty; 00121 }; 00122 00123 #endif // FUNC_H