static VALUE m_missing(int argc, VALUE* argv, VALUE self) { bool assignment = false; if (global_object.isNull()) return Qnil; // store the method name and arguments in separate variables VALUE method_name, args; rb_scan_args(argc, argv, "1*", &method_name, &args); char* name = strdup(rb_id2name(SYM2ID(method_name))); // Check if this is an assignment if (name[strlen(name) - 1] == '=') { name[strlen(name) - 1] = '\0'; assignment = true; } // If we can't find this property perhaps we should return // the same property name except capitalized. KValueRef v = global_object->Get(name); if (v->IsUndefined()) { name[0] = toupper(name[0]); v = global_object->Get(name); } // Okay, maybe not if (v->IsUndefined()) name[0] = tolower(name[0]); VALUE rval; if (assignment) // Assignment { rval = rb_ary_entry(args, 0); KValueRef val = RubyUtils::ToKrollValue(rval); global_object->Set(name, val); } else if (v->IsMethod()) // Method call { rval = RubyUtils::GenericKMethodCall(v->ToMethod(), args); } else // Plain old access { rval = RubyUtils::ToRubyValue(v); } return rval; }
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); }
void KPHPArrayObject::AddKrollValueToPHPArray(KValueRef value, zval *phpArray) { if (value->IsNull() || value->IsUndefined()) { add_next_index_null(phpArray); } else if (value->IsBool()) { if (value->ToBool()) add_next_index_bool(phpArray, 1); else add_next_index_bool(phpArray, 0); } else if (value->IsNumber()) { /* No way to check whether the number is an integer or a double here. All Kroll numbers are doubles, so return a double. This could cause some PHP to function incorrectly if it's doing strict type checking. */ add_next_index_double(phpArray, value->ToNumber()); } else if (value->IsString()) { add_next_index_stringl(phpArray, (char *) value->ToString(), strlen(value->ToString()), 1); } else if (value->IsObject()) { /*TODO: Implement*/ } else if (value->IsMethod()) { /*TODO: Implement*/ } else if (value->IsList()) { zval *phpValue; AutoPtr<KPHPArrayObject> pl = value->ToList().cast<KPHPArrayObject>(); if (!pl.isNull()) phpValue = pl->ToPHP(); else phpValue = PHPUtils::ToPHPValue(value); add_next_index_zval(phpArray, phpValue); } }
KValueRef KDelegatingObject::Get(const char *name) { Poco::Mutex::ScopedLock lock(mutex); KValueRef val = local->Get(name); if (!val->IsUndefined()) { // We want properties of the local object to // override // properties set on the global object. return val; } else { // If the property isn't found on the local object, search // for it in the global object. return this->global->Get(name); } }
void KObject::GetStringList(const char *name, std::vector<std::string> &list) { KValueRef prop = this->Get(name); if(!prop->IsUndefined() && prop->IsList()) { KListRef values = prop->ToList(); if (values->Size() > 0) { for (unsigned int c = 0; c < values->Size(); c++) { KValueRef v = values->At(c); if (v->IsString()) { const char *s = v->ToString(); list.push_back(s); } } } } }
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()); } }