Changeset 247 for cpp/frams/vm/classes/3dobject.cpp
- Timestamp:
- 11/07/14 17:51:01 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/vm/classes/3dobject.cpp
r241 r247 472 472 {return ExtObject(&getStaticParam(),p);} 473 473 474 ParamEntry* ReferenceObj::getStaticParamtab()475 {476 #define FIELDSTRUCT ReferenceObj477 static ParamEntry paramtab[]=478 {479 {"Ref",1,5,"Ref","Reference objects. Useful for returning things from functions.\n\nExample:\nvar x=111;\nsquare(&x);// '&' creates the Reference object\nSimulator.print(x);//x is now 12321\n\nfunction square(r)\n{r.value=r.value*r.value;}\n//square receives the Reference objects and changes its 'value' field"},480 481 {"value",0,PARAM_NOSTATIC,"value","x",GETSET(value),},482 {"newS",0,0,"create new reference","p",PROCEDURE(p_newS),"(for internal use only) use &variablename to create Ref objects.",},483 {"newO",0,0,"create new reference","p",PROCEDURE(p_newO),"(for internal use only) use &variablename to create Ref objects.",},484 {"copyFrom",0,0,"copy the reference","p(oRef)",PROCEDURE(p_copyFrom),"make the reference point to the same target,"},485 {"toString",0,PARAM_READONLY | PARAM_NOSTATIC,"textual form","s",GETONLY(toString),},486 {0,0,0,},487 };488 #undef FIELDSTRUCT489 return paramtab;490 }491 492 Param& ReferenceObj::getStaticParam()493 {494 #ifdef __CODEGUARD__495 static ReferenceObj static_referenceobj;496 static Param static_refobjectparam(getStaticParamtab(),&static_referenceobj);497 #else498 static Param static_refobjectparam(getStaticParamtab());499 #endif500 return static_refobjectparam;501 }502 503 void ReferenceObj::p_newS(ExtValue *args,ExtValue *ret)504 {505 *ret=makeDynamicObject(new ReferenceObj((ExtValue*)args->getInt()));506 }507 508 void ReferenceObj::p_newO(ExtValue *args,ExtValue *ret)509 {510 if (args[0].type==TInt)511 *ret=makeDynamicObject(new ReferenceObj(args[1].getObject(),args[0].getInt()));512 else513 *ret=makeDynamicObject(new ReferenceObj(args[1].getObject(),args[0].getString()));514 }515 516 void ReferenceObj::p_copyFrom(ExtValue *args,ExtValue *ret)517 {518 ReferenceObj* other=fromObject(args[0]);519 if (other)520 {521 value=other->value;522 obj=other->obj;523 prop=other->prop;524 }525 }526 527 void ReferenceObj::get_toString(ExtValue *ret)528 {529 SString s="(";530 static SListTempl<ReferenceObj*> trace;531 if (trace.find(this)>=0)532 s+="...";533 else534 {535 trace+=this;536 if (value)537 s+=value->getString();538 else539 {540 ExtValue v;541 Param tmp_param;542 ParamInterface *pi=obj.getParamInterface(tmp_param);543 pi->get(prop,v);544 s+=v.getString();545 }546 trace-=this;547 }548 s+=")";549 ret->setString(s);550 }551 552 void ReferenceObj::get_value(ExtValue *ret)553 {554 if (value)555 *ret=*value;556 else557 {558 Param tmp_param;559 ParamInterface *pi=obj.getParamInterface(tmp_param);560 pi->get(prop,*ret);561 }562 }563 564 int ReferenceObj::set_value(const ExtValue *val)565 {566 if (value)567 *value=*val;568 else569 {570 Param tmp_param;571 ParamInterface *pi=obj.getParamInterface(tmp_param);572 pi->set(prop,*val);573 }574 return PSET_CHANGED;575 }576 577 ReferenceObj::ReferenceObj(const ExtObject &o,const SString &p)578 :value(0),obj(o)579 {580 Param tmp_param;581 ParamInterface *pi=obj.getParamInterface(tmp_param);582 prop=pi->findId(p);583 }584 585 ExtObject ReferenceObj::makeDynamicObject(ReferenceObj* r)586 {return ExtObject(&getStaticParam(),r);}587 588 ReferenceObj* ReferenceObj::fromObject(const ExtValue& v)589 {590 return (ReferenceObj*)v.getObjectTarget(getStaticParam().getName());591 }592 593 474 ///////////// 594 475
Note: See TracChangeset
for help on using the changeset viewer.