Example #1
0
void UserWindow::_GetContextMenu(const kroll::ValueList& args, kroll::SharedValue result)
{
	SharedKList menu = this->GetContextMenu();
	if (!menu.isNull())
	{
		result->SetList(menu);
	}
	else
	{
		result->SetUndefined();
	}
}
	void AppBinding::GetArguments(const ValueList& args, SharedValue result)
	{
		static SharedKList argList(0);
		if (argList.isNull())
		{
			// Skip the first argument which is the filename to the executable
			argList = new StaticBoundList();
			for (int i = 1; i < host->GetCommandLineArgCount(); i++)
				argList->Append(Value::NewString(host->GetCommandLineArg(i)));
		}

		result->SetList(argList);
	}
Example #3
0
	static VALUE RubyKListEach(VALUE self)
	{
		SharedValue* dval = NULL;
		Data_Get_Struct(self, SharedValue, dval);
		SharedKList list = (*dval)->ToList();

		if (list.isNull() || !rb_block_given_p())
			return Qnil;

		for (unsigned int i = 0; i < list->Size(); i++)
		{
			VALUE rubyValue = RubyUtils::ToRubyValue(list->At(i));
			rb_yield(rubyValue);
		}
		return self;
	}
Example #4
0
	static VALUE RubyKListLength(int argc, VALUE *argv, VALUE self)
	{
		SharedValue* dval = NULL;
		Data_Get_Struct(self, SharedValue, dval);
		SharedKList klist = (*dval)->ToList();

		// TODO: We should raise an exception instead
		if (klist.isNull())
			return Qnil;

		if (argc > 0)
		{
			rb_raise(rb_eNoMethodError, "wrong number of arguments (%d for 0)", argc);
			return Qnil;
		}
		else
		{
			return INT2NUM(klist->Size());
		}
	}
Example #5
0
	static VALUE RubyKListSetElt(int argc, VALUE *argv, VALUE self)
	{
		SharedValue* dval = NULL;
		Data_Get_Struct(self, SharedValue, dval);
		SharedKList klist = (*dval)->ToList();

		// TODO: We should raise an exception instead
		if (klist.isNull() || argc < 2)
			return Qnil;
		// TODO: Maybe we should raise an exception instead
		if (TYPE(argv[0]) != T_FIXNUM)
			return Qnil;

		int idx = NUM2INT(argv[0]);
		if (idx < 0)
			return Qnil;

		SharedValue value = RubyUtils::ToKrollValue(argv[1]);
		klist->SetAt(idx, value);

		return argv[1];
	}
Example #6
0
	static VALUE RubyKListGetElt(int argc, VALUE *argv, VALUE self)
	{
		SharedValue* dval = NULL;
		Data_Get_Struct(self, SharedValue, dval);
		SharedKList list = (*dval)->ToList();

		// TODO: We should raise an exception instead
		if (list.isNull() || argc < 1)
			return Qnil;

		int idx = -1;
		if (TYPE(argv[0]) != T_FIXNUM || ((idx = NUM2INT(argv[0])) < 0))
			return Qnil;

		if (idx >= 0 && idx < (int) list->Size())
		{
			SharedValue v = list->At(idx);
			return RubyUtils::ToRubyValue(v);
		}
		else
		{
			return Qnil;
		}
	}