Beispiel #1
0
int KObject::GetInt(const char* name, int defaultValue)
{
    KValueRef prop = this->Get(name);
    if (prop->IsInt())
    {
        return prop->ToInt();
    }
    else
    {
        return defaultValue;
    }
}
 std::string RubyEvaluator::GetContextId(KObjectRef global)
 {
     static int nextId = 0;
     int cid = 0;
     KValueRef idv = global->Get("__ruby_module_id__");
     if (idv->IsUndefined())
     {
         cid = nextId++;
         global->Set("__ruby_module_id__", Value::NewInt(cid));
     }
     else
     {
         cid = idv->ToInt();
     }
     return std::string("$windowProc") + KList::IntToChars(cid);
 }
Beispiel #3
0
 void convert (Statement &select, KValueRef arg)
 {
     if (arg->IsString())
     {
         std::string *s = new std::string(arg->ToString()); 
         select , use(*s);
         strings.push_back(s);
     }
     else if (arg->IsInt())
     {
         int *i = new int(arg->ToInt());
         select , use(*i);
         ints.push_back(i);
     }
     else if (arg->IsDouble())
     {
         double *d = new double(arg->ToDouble());
         select , use(*d);
         doubles.push_back(d);
     }
     else if (arg->IsBool())
     {
         bool *b = new bool(arg->ToBool());
         select , use(*b);
         bools.push_back(b);
     }
     else if (arg->IsNull() || arg->IsUndefined())
     {
         // in this case, we bind a null string (dequoted)
         std::string *s = new std::string("null");
         select , use(s);
         strings.push_back(s);
     }
     else
     {
         throw ValueException::FromFormat("Unsupport type for argument: %s",
             arg->GetType().c_str());
     }
 } 
Beispiel #4
0
 Logger::Level APIBinding::ValueToLevel(KValueRef v)
 {
     if (v->IsString())
     {
         string levelString = v->ToString();
         return Logger::GetLevel(levelString);
     }
     else if (v->IsObject())
     {
         SharedString ss = v->ToObject()->DisplayString();
         return Logger::GetLevel(*ss);
     }
     else if (v->IsNumber())
     {
         return (Logger::Level) v->ToInt();
     }
     else // return the appropriate default
     {
         string levelString = "";
         return Logger::GetLevel(levelString);
     }
 }
Beispiel #5
0
 static void GetBytes(KValueRef value, std::vector<BytesRef>& blobs)
 {
     if (value->IsObject())
     {
         blobs.push_back(value->ToObject().cast<Bytes>());
     }
     else if (value->IsString())
     {
         blobs.push_back(new Bytes(value->ToString()));
     }
     else if (value->IsList())
     {
         KListRef list = value->ToList();
         for (size_t j = 0; j < list->Size(); j++)
         {
             GetBytes(list->At((int)j), blobs);
         }
     }
     else if (value->IsNumber())
     {
         blobs.push_back(new Bytes(value->ToInt()));
     }
 }