Value Iterator::ToList(Environment &env, bool alwaysListFlag, bool excludeNilFlag) { Signal &sig = env.GetSignal(); if (IsInfinite()) { SetError_InfiniteNotAllowed(sig); return Value::Nil; } Value result; Object_list *pObjList = nullptr; size_t cnt = 0; Value value; if (alwaysListFlag) { pObjList = result.InitAsList(env); } while (Next(env, value)) { if (pObjList == nullptr && !value.IsUndefined()) { pObjList = result.InitAsList(env, cnt, Value::Nil); } if (value.IsValid()) { if (pObjList == nullptr) { pObjList = result.InitAsList(env, cnt, Value::Nil); } pObjList->Add(value); } else if (excludeNilFlag) { // nothing to do } else if (pObjList != nullptr) { pObjList->Add(value); } cnt++; } if (sig.IsSignalled()) return Value::Nil; return result; }
Value Iterator::FindMinMaxIndices(Environment &env, bool maxFlag) { Signal &sig = env.GetSignal(); if (IsInfinite()) { SetError_InfiniteNotAllowed(sig); return Value::Nil; } Value valueHit; if (!Next(env, valueHit)) return Value::Nil; Value result; int idxHit = GetIndexCur(); Object_list *pObjListResult = result.InitAsList(env); pObjListResult->Add(Value(idxHit)); Value value; while (Next(env, value)) { int cmp = Value::Compare(env, valueHit, value); if (sig.IsSignalled()) return Value::Nil; if (maxFlag) cmp = -cmp; if (cmp > 0) { int idxHit = GetIndexCur(); valueHit = value; pObjListResult->Clear(); pObjListResult->Add(Value(idxHit)); } else if (cmp == 0) { int idxHit = GetIndexCur(); pObjListResult->Add(Value(static_cast<Number>(idxHit))); } } if (sig.IsSignalled()) return Value::Nil; return result; }
Value Formatter::FormatIterator(Environment &env, const char *format, IteratorOwner &iterOwner) { Signal &sig = env.GetSignal(); Value result; Object_list *pObjListResult = result.InitAsList(env); ValueList valList; while (iterOwner.Next(env, valList)) { String str = FormatValueList(sig, format, valList); if (sig.IsSignalled()) return Value::Nil; pObjListResult->Add(Value(str)); } if (sig.IsSignalled()) return Value::Nil; return result; }
Gura_ImplementMethod(wx_Pen, GetDashes) { Signal &sig = env.GetSignal(); Object_wx_Pen *pThis = Object_wx_Pen::GetObjectThis(arg); if (pThis->IsInvalid(sig)) return Value::Nil; wxDash *dashes; int rtn = pThis->GetEntity()->GetDashes(&dashes); Value result; Object_list *pObjList = result.InitAsList(env); pObjList->Reserve(rtn); for (int i = 0; i < rtn; i++) { pObjList->Add(Value(dashes[i])); } return ReturnValue(env, arg, result); }
Gura_ImplementMethod(wx_DataObject, GetAllFormats) { Signal &sig = env.GetSignal(); Object_wx_DataObject *pThis = Object_wx_DataObject::GetObjectThis(arg); if (pThis->IsInvalid(sig)) return Value::Nil; wxDataObject::Direction dir = wxDataObject::Get; size_t n = pThis->GetEntity()->GetFormatCount(dir); if (arg.IsValid(0)) dir = static_cast<wxDataObject::Direction>(arg.GetInt(0)); Value rtn; wxDataFormat *formats = new wxDataFormat[n]; pThis->GetEntity()->GetAllFormats(formats, dir); Object_list *pObjList = rtn.InitAsList(env); pObjList->Reserve(n); for (size_t i = 0; i < n; i++) { pObjList->Add(Value(new Object_wx_DataFormat(new wxDataFormat(formats[i]), nullptr, OwnerTrue))); } delete[] formats; return rtn; }
Value Object_interp::ConvFromTclObj(Environment &env, Signal &sig, Tcl_Obj *objPtr) { Tcl_ObjType *typePtr = objPtr->typePtr; if (typePtr == nullptr) { return Value(objPtr->bytes, objPtr->length); } else if (typePtr == ObjType_boolean) { int value; ::Tcl_GetBooleanFromObj(_interp, objPtr, &value); return Value(value? true : false); } else if (typePtr == ObjType_bytearray) { int length; unsigned char *binary = ::Tcl_GetByteArrayFromObj(objPtr, &length); return Value(new Object_binary(env, Binary(reinterpret_cast<char *>(binary), length), true)); } else if (typePtr == ObjType_double) { double value; ::Tcl_GetDoubleFromObj(_interp, objPtr, &value); return Value(value); } else if (typePtr == ObjType_int) { int value; ::Tcl_GetIntFromObj(_interp, objPtr, &value); return Value(value); } else if (typePtr == ObjType_list) { int length; ::Tcl_ListObjLength(_interp, objPtr, &length); Value result; Object_list *pObjList = result.InitAsList(env); pObjList->Reserve(length); for (int i = 0; i < length; i++) { Tcl_Obj *objElemPtr; ::Tcl_ListObjIndex(_interp, objPtr, i, &objElemPtr); pObjList->Add(ConvFromTclObj(env, sig, objElemPtr)); if (sig.IsSignalled()) return Value::Nil; } return result; } else if (typePtr == ObjType_string) { int length; char *value = ::Tcl_GetStringFromObj(objPtr, &length); return Value(value); } return Value(objPtr->bytes, objPtr->length); }