DaoValue* DaoObject_GetField( DaoObject *self, const char *name ) { DaoValue *res = NULL; DString str = DString_WrapChars( name ); DaoObject_GetData( self, & str, & res, self ); return res; }
static DaoValue* DaoObject_DoGetField( DaoValue *self, DaoString *name, DaoProcess *proc ) { DaoObject *object = (DaoObject*) self; DaoObject *host = proc->activeObject; DaoClass *hostClass = host ? host->defClass : NULL; DaoValue *value = NULL; int rc = DaoObject_GetData( object, name->value, & value, host ); if( rc ){ DaoRoutine *rout; DString *field = proc->string; DString_SetChars( field, "." ); DString_Append( field, name->value ); rout = DaoClass_FindMethod( object->defClass, field->chars, hostClass ); if( rout != NULL ){ rc = DaoProcess_PushCall( proc, rout, self, NULL, 0 ); }else{ DaoValue *arg = (DaoValue*) name; rout = DaoClass_FindMethod( object->defClass, ".", hostClass ); if( rout != NULL ) rc = DaoProcess_PushCall( proc, rout, self, & arg, 1 ); } if( rout == NULL ) return NULL; }else{ DaoProcess_PutValue( proc, value ); } if( rc ) DaoProcess_RaiseError( proc, daoExceptionNames[rc], name->value->chars ); return NULL; }
static int DaoObject_Serialize( DaoObject *self, DString *serial, DaoNamespace *ns, DaoProcess *proc, DString *buf, DMap *omap ) { DaoType *type; DaoValue *value = NULL; DaoValue *selfpar = (DaoValue*) self; DString name = DString_WrapMBS( "serialize" ); int errcode = DaoObject_GetData( self, & name, & value, NULL ); if( errcode || value == NULL || value->type != DAO_ROUTINE ) return 0; if( DaoProcess_Call( proc, (DaoRoutine*)value, selfpar, NULL, 0 ) ) return 0; type = DaoNamespace_GetType( ns, proc->stackValues[0] ); DaoValue_Serialize2( proc->stackValues[0], serial, ns, proc, type, buf, omap ); return 1; }
int DaoObject_InvokeMethod( DaoObject *self, DaoObject *othis, DaoProcess *proc, DString *name, DaoValue *P[], int N, int ignore_return, int execute ) { DaoValue *V = NULL; DaoValue *O = (DaoValue*)self; int errcode = DaoObject_GetData( self, name, &V, othis ); if( errcode ) return errcode; if( V == NULL || V->type != DAO_ROUTINE ) return DAO_ERROR_TYPE; if( DaoProcess_PushCallable( proc, (DaoRoutine*) V, O, P, N ) ) goto InvalidParam; if( ignore_return ) DaoProcess_InterceptReturnValue( proc ); if( execute ) DaoProcess_Execute( proc ); return 0; InvalidParam: DaoProcess_ShowCallError( proc, (DaoRoutine*)V, O, P, N, DVM_CALL ); return DAO_ERROR_PARAM; }
static void DaoObject_Core_GetField( DaoValue *self0, DaoProcess *proc, DString *name ) { DaoObject *self = & self0->xObject; DaoValue *value = NULL; int rc = DaoObject_GetData( self, name, & value, proc->activeObject ); if( rc ){ DString *field = proc->string; DString_SetChars( field, "." ); DString_Append( field, name ); rc = DaoObject_InvokeMethod( self, proc->activeObject, proc, field, NULL,0,0,0 ); if( rc == DAO_ERROR_FIELD_NOTEXIST ){ DaoString str = {DAO_STRING,0,0,0,1,NULL}; DaoValue *pars = (DaoValue*) & str; str.value = name; DString_SetChars( field, "." ); rc = DaoObject_InvokeMethod( self, proc->activeObject, proc, field, &pars,1,0,0 ); } }else{ DaoProcess_PutValue( proc, value ); } if( rc ) DaoProcess_RaiseException( proc, daoExceptionNames[rc], name->chars, NULL ); }
static void STD_Callable( DaoProcess *proc, DaoValue *p[], int N ) { DaoValue *p0 = p[0]; daoint *res = DaoProcess_PutInteger( proc, 0 ); if( p0 == NULL || p0->type == 0 ){ *res = 0; return; } switch( p0->type ){ case DAO_CLASS : case DAO_ROUTINE : *res = 1; break; case DAO_OBJECT : { DaoObject *object = & p0->xObject; DString *mbs = DString_New(1); DString_SetMBS( mbs, "()" ); DaoObject_GetData( object, mbs, & p0, proc->activeObject ); DString_Delete( mbs ); if( p0 && p0->type == DAO_ROUTINE ) *res = 1; break; } case DAO_CTYPE : { DaoType *type = p0->xCdata.ctype; *res = DaoType_FindFunctionMBS( type, type->typer->name ) != NULL; break; } case DAO_CDATA : case DAO_CSTRUCT : { *res = DaoType_FindFunctionMBS( p0->xCdata.ctype, "()" ) != NULL; break; } default : break; } }