00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef neo_script_lua_classrep_h
00022 #define neo_script_lua_classrep_h
00023
00029 #include "../../core/platform.h"
00030
00031 #if NEO_ENABLE_SCRIPT_LUA
00032
00033 #include "../../core/hashtable.h"
00034 #include "../../core/type.h"
00035 #include "constructor.h"
00036
00037 extern "C" { struct lua_State; }
00038
00039 namespace neo {
00040 namespace script {
00041 namespace lua {
00042
00043 class ClassBase;
00044 class Object;
00045 class ClassRegistry;
00046 class GetSetBase;
00047 class MethodRep;
00048
00049 typedef void ( *Destructor )( void* );
00050
00051 class RuntimeTypeCast
00052 {
00053 public:
00054 inline virtual ~RuntimeTypeCast() {};
00055 virtual ptrdiff_t castPointerOffset( char* p_ptr ) = 0;
00056 virtual RuntimeTypeCast* clone() = 0;
00057 };
00058
00059 template < class Derived, class Base > class RuntimeTypeCastImpl : public RuntimeTypeCast
00060 {
00061 public:
00062 inline virtual ptrdiff_t castPointerOffset( char* p_ptr ) { return core::castPointerOffset< Derived, Base >( reinterpret_cast< Derived* >( p_ptr ) ); }
00063 virtual RuntimeTypeCast* clone() { return new RuntimeTypeCastImpl; }
00064 };
00065
00066 class BaseClassDesc
00067 {
00068 public:
00069
00070 const std::type_info* _p_type;
00071 int _offset;
00072 RuntimeTypeCast* _p_caster;
00073 ClassRep* _p_crep;
00074 inline BaseClassDesc( const std::type_info* p_type = 0, int offset = 0, RuntimeTypeCast* p_caster = 0, ClassRep* p_crep = 0 );
00075 inline BaseClassDesc( const BaseClassDesc& desc );
00076 inline ~BaseClassDesc();
00077 };
00078
00079 class ClassRep
00080 {
00081 public:
00082
00084
00090 ClassRep( lua_State* p_state, const std::type_info* p_type, const char* p_name, Destructor destructor );
00091
00093 ~ClassRep();
00094
00096
00099 int isOfType( const std::type_info* p_type ) const;
00100
00102
00106 int getConversionOffset( const std::type_info* p_type, char* p_ptr ) const;
00107
00108 int getTable( lua_State* p_state );
00109
00110 bool setTable( lua_State* p_state );
00111
00112 inline const char* getName() const { return _p_name; }
00113
00114 static int dispatchGetTable( lua_State* p_state );
00115
00116 static int dispatchSetTable( lua_State* p_state );
00117
00118 static int dispatchOperator( lua_State* p_state );
00119
00120 static int dispatchConstructor( lua_State* p_state );
00121
00122 static int dispatchMethod( lua_State* p_state );
00123
00124 static int getTableStatic( lua_State* p_state );
00125 int getTableStaticClass( lua_State* p_state );
00126
00127 static ClassRep* isClass( lua_State* p_state, int index );
00128
00129 private:
00130
00132 int _refSelf;
00133
00135 const char* _p_name;
00136
00138 const std::type_info* _p_type;
00139
00141 core::HashTable< const char*, MethodRep > _methods;
00142
00144 core::HashTable< const char*, MethodRep > _methodsStatic;
00145
00147 ConstructorRep _ctor;
00148
00150 core::Array< MethodRep > _operators;
00151
00153 core::HashTable< const char*, GetSetBase* > _getters;
00154
00156 core::HashTable< const char*, GetSetBase* > _setters;
00157
00159 core::HashTable< const char*, int > _enums;
00160
00162 core::HashTable< const char*, GetSetBase* > _statics;
00163
00165 core::Array< BaseClassDesc > _bases;
00166
00168 Destructor _dtor;
00169
00170 friend class ClassBase;
00171 friend class Object;
00172 friend class ClassRegistry;
00173 };
00174
00175 #include "classrep.inl"
00176
00177 }
00178 }
00179 }
00180
00181 #endif
00182
00183 #endif