1
#ifndef __KSCRIPT_OBJECT_H__
2
#define __KSCRIPT_OBJECT_H__
9
#include "kscript_ptr.h"
10
#include "kscript_context.h"
11
#include "kscript_class.h"
12
#include "kscript_func.h"
13
#include "kscript_struct.h"
14
#include "kscript_proxy.h"
15
#include "kscript_qobject.h"
19
class KSObject : public QShared
22
typedef KSSharedPtr<KSObject> Ptr;
24
enum Status { Dead, Alive };
26
KSObject( KSClass* c );
31
KSModule* module() { return m_class->module(); }
32
KSSubScope* scope() { return &m_scope; }
33
KSNamespace* instanceNameSpace() { return &m_space; }
34
const KSNamespace* instanceNameSpace() const { return &m_space; }
36
const KSClass* getClass() const { return m_class; }
37
KSClass* getClass() { return m_class; }
39
Status status() { return m_status; }
40
void setStatus( Status s ) { m_status = s; }
42
bool connect( const QString& sig, KSObject* r, KSValue* s );
44
void disconnect( KSObject* o );
45
void disconnect( KSObject* o, KSValue* _slot );
46
bool emitSignal( const QString& name, KSContext& context );
48
void removeSender( KSObject* o ) { m_sender.removeRef( o ); }
49
void appendSender( KSObject* o ) { m_sender.append( o ); }
52
* Implements a KScript function of the same name.
54
bool disconnect( KSContext& context );
56
* Implements a KScript function of the same name.
58
bool inherits( KSContext& context );
60
* Implements a KScript function of the same name.
62
bool isA( KSContext& context );
65
* If @ref KSContext::leftExpr retruns TRUE for the given context,
66
* then a new member is added to the object if it did not exist.
67
* Otherwise 0 is returned for a non existing member.
68
* This function may nevertheless set a exception if a member is known but if
69
* it could not be read for some reason.
71
virtual KSValue::Ptr member( KSContext&, const QString& name );
73
* May set a exception if the member could not be set.
75
virtual bool setMember( KSContext&, const QString& name, const KSValue::Ptr& v );
78
* When getting a pointer to a KSObject via @ref KSValue::objectValue this function
79
* helps to do some dynamic casting.
81
virtual bool inherits( const char* name ) { return ( strcmp( name, "KSObject" ) == 0 ); }
90
typedef QValueList<Signal> SignalList;
91
typedef QMap<QString,SignalList> SignalMap;
93
SignalList* findSignal( const QString& name, bool insert = false );
95
virtual bool destructor();
99
* This namespace holds the variables of this instance.
103
* This scope holds all namespaces of base classes and the local
108
* This objects class.
114
QList<KSObject> m_sender;
117
class KSScriptObject : public KSObject
120
KSScriptObject( KSClass* c ) : KSObject( c ) { }
123
bool inherits( const char* name ) { return ( strcmp( name, "KSScriptObject" ) == 0 || KSObject::inherits( name ) ); }
126
virtual bool destructor();
130
* A method holds a reference to some instance and some function. The function
131
* may be of the type @ref KSFunction, KSBuiltinFunction or KSStructBuiltinFunction.
132
* The instance may be a @ref KSObject or @ref KSStruct or derived types.
134
class KSMethod : public QShared
137
KSMethod( KSModule* m, const KSValue::Ptr& obj, const KSValue::Ptr& func ) : QShared(), m_object( obj ), m_func( func ), m_module( m ) { }
139
* Use this method if the function is KSBuiltinFunction or KSStructBuiltinFunction.
140
* In this case we pass the name of the method. No copy of this name is made and the
141
* destructor does not free the string. So you should only pass constants here.
143
KSMethod( KSModule* m, const KSValue::Ptr& obj, const KSValue::Ptr& func, const QString& name )
144
: QShared(), m_object( obj ), m_func( func ), m_module( m ), m_methodName( name ) { }
145
virtual ~KSMethod() { }
147
bool call( KSContext& context );
149
KSValue* object() { return m_object; }
150
KSValue* function() { return m_func; }
152
KSModule* module() { return m_module; }
154
QString name() { return ( m_methodName.isEmpty() ? m_func->functionValue()->name() : m_methodName ); }
157
KSValue::Ptr m_object;
161
QString m_methodName;
164
class KSProperty : public QShared
167
KSProperty( const KSObject::Ptr& obj, const QString& name ) { m_obj = obj; m_name = name; }
168
KSProperty( const KSStruct::Ptr& struc, const QString& name ) { m_struct = struc; m_name = name; }
169
KSProperty( const KSProxy::Ptr& proxy, const QString& name ) { m_proxy = proxy; m_name = name; }
170
KSProperty( const KSModule::Ptr& m, const QString& name ) { m_module = m; m_name = name; }
171
KSProperty( const KSQObject::Ptr& m, const QString& name ) { m_qobject = m; m_name = name; }
173
virtual ~KSProperty() { }
175
QString name() { return m_name; }
177
virtual bool set( KSContext&, const KSValue::Ptr& v );
181
KSStruct::Ptr m_struct;
182
KSProxy::Ptr m_proxy;
183
KSModule::Ptr m_module;
184
KSQObject::Ptr m_qobject;