コード例 #1
0
AutoPtr<StaticBoundObject> ScopeMethodDelegate::CreateDelegate(KObjectRef global, KObjectRef bo)
{
	AutoPtr<StaticBoundObject> scope = new StaticBoundObject();
	SharedStringList keys = bo->GetPropertyNames();
	StringList::iterator iter = keys->begin();

	while(iter!=keys->end())
	{
		SharedString key_ptr = (*iter++);
		std::string key = *key_ptr;
		KValueRef value = bo->Get(key.c_str());

		if (key == "set")
		{
			KMethodRef d = new ScopeMethodDelegate(SET, global, scope, value->ToMethod());
			KValueRef v = Value::NewMethod(d);
			scope->Set(key.c_str(), v);
		}
		else if (key == "get")
		{
			KMethodRef d = new ScopeMethodDelegate(GET, global, scope, value->ToMethod());
			KValueRef v = Value::NewMethod(d);
			scope->Set(key.c_str(), v);
		}
		else
		{
			scope->Set(key.c_str(), value);
		}

	}
	return scope;
}
コード例 #2
0
ファイル: script.cpp プロジェクト: mital/kroll
	KValueRef Script::Evaluate(const char *mimeType, const char *name, const char *code, KObjectRef scope)
	{
		KObjectRef evaluator = this->FindEvaluatorWithMethod("canEvaluate", mimeType);
		if (!evaluator.isNull())
		{
			KMethodRef evaluate = evaluator->GetMethod("evaluate");
			if (!evaluate.isNull())
			{
				ValueList args;
				args.push_back(Value::NewString(mimeType));
				args.push_back(Value::NewString(name));
				args.push_back(Value::NewString(code));
				args.push_back(Value::NewObject(scope));
				return evaluate->Call(args);
			}
			else
			{
				throw ValueException::FromFormat(
					"Error evaluating: No \"evaluate\" method found on evaluator for mimeType: \"%s\"", mimeType);
			}
		}
		else
		{
			throw ValueException::FromFormat("Error evaluating: No evaluator found for mimeType: \"%s\"", mimeType);
		}
	}
コード例 #3
0
    static void MergePyGlobalsWithContext(PyObject* globals, KObjectRef context)
    {
		// Avoid compiler warnings
		PyObject *items = PyObject_CallMethod(globals, (char*) "items", NULL);
		if (items == NULL)
			return;

		PyObject *iterator = PyObject_GetIter(items);
		if (iterator == NULL)
			return;

		PyObject *item;
		while ((item = PyIter_Next(iterator)))
		{
			PyObject* k = PyTuple_GetItem(item, 0);
			PyObject* v = PyTuple_GetItem(item, 1);
			std::string sk = PythonUtils::ToString(k);
			if (sk.find("__") != 0)
			{
				KValueRef newValue = PythonUtils::ToKrollValue(v);
				KValueRef existingValue = context->Get(sk.c_str());
				if (!newValue->Equals(existingValue))
				{
					context->Set(sk.c_str(), newValue);
				}
			}
			Py_DECREF(item);
		}
    }
コード例 #4
0
ファイル: url.cpp プロジェクト: Val9/titanium_desktop
	char* PreprocessURLCallback(const char* url, KeyValuePair* headers, char** mimeType)
	{
		Logger* logger = Logger::Get("UI.URL");

		KObjectRef scope = new StaticBoundObject();
		KObjectRef kheaders = new StaticBoundObject();
		while (headers->key)
		{
			kheaders->SetString(headers->key, headers->value);
			headers++;
		}

		try
		{
			AutoPtr<PreprocessData> result = 
				Script::GetInstance()->Preprocess(url, scope);
			*mimeType = strdup(result->mimeType.c_str());
			return strdup(result->data->Pointer());
		}
		catch (ValueException& e)
		{
			logger->Error("Error in preprocessing: %s", e.ToString().c_str());
		}
		catch (...)
		{
			logger->Error("Unknown Error in preprocessing");
		}

		return NULL;
	}
コード例 #5
0
	void AppBinding::CreateProperties(const ValueList& args, KValueRef result)
	{
		AutoPtr<PropertiesBinding> properties = new PropertiesBinding();
		result->SetObject(properties);
		
		if (args.size() > 0 && args.at(0)->IsObject())
		{
			KObjectRef p = args.at(0)->ToObject();
			SharedStringList names = p->GetPropertyNames();
			for (size_t i = 0; i < names->size(); i++)
			{
				KValueRef value = p->Get(names->at(i));
				ValueList setterArgs;
				setterArgs.push_back(Value::NewString(names->at(i)));
				setterArgs.push_back(value);
				PropertiesBinding::Type type;
				
				if (value->IsList()) type = PropertiesBinding::List;
				else if (value->IsInt()) type = PropertiesBinding::Int;
				else if (value->IsDouble()) type = PropertiesBinding::Double;
				else if (value->IsBool()) type = PropertiesBinding::Bool;
				else type = PropertiesBinding::String;
				
				properties->Setter(setterArgs, type);
			}
		}
	}
コード例 #6
0
void Notification::Configure(KObjectRef properties)
{
	this->title = properties->GetString("title");
	this->message = properties->GetString("message");
	this->iconURL = properties->GetString("icon");
	this->timeout = properties->GetInt("timeout", -1);
	this->clickedCallback = properties->GetMethod("callback");
}
コード例 #7
0
ファイル: ruby_module.cpp プロジェクト: mital/kroll
	void RubyModule::Stop()
	{
		KObjectRef global = this->host->GetGlobalObject();
		global->Set("Ruby", Value::Undefined);
		Script::GetInstance()->RemoveScriptEvaluator(this->binding);
		this->binding = NULL;
		RubyModule::instance_ = NULL;

		ruby_cleanup(0);
	}
コード例 #8
0
	void UIBinding::_SetContextMenu(const ValueList& args, KValueRef result)
	{
		args.VerifyException("setContextMenu", "o|0");
		KObjectRef argObj = args.GetObject(0, NULL);
		AutoMenu menu = NULL;

		if (!argObj.isNull())
		{
			menu = argObj.cast<Menu>();
		}
		this->SetContextMenu(menu);
	}
コード例 #9
0
ファイル: php_module.cpp プロジェクト: toisoftware/TideSDK
void PHPModule::InitializeBinding()
{
    PHPModule::mimeType = SG(default_mimetype);

    KObjectRef global = this->host->GetGlobalObject();
    this->binding = new PHPEvaluator();
    global->Set("PHP", Value::NewObject(this->binding));
    Script::GetInstance()->AddScriptEvaluator(this->binding);

    zval *titaniumValue = PHPUtils::ToPHPValue(Value::NewObject(global));
    ZEND_SET_SYMBOL(&EG(symbol_table), PRODUCT_NAME, titaniumValue);
}
コード例 #10
0
ファイル: ruby_module.cpp プロジェクト: mital/kroll
	void RubyModule::InitializeBinding()
	{
		// Expose the Ruby evaluator into Kroll
		KObjectRef global = this->host->GetGlobalObject();
		this->binding = new RubyEvaluator();
		global->Set("Ruby", Value::NewObject(binding));
		Script::GetInstance()->AddScriptEvaluator(this->binding);
		
		// Bind the API global constant
		VALUE ruby_api_val = RubyUtils::KObjectToRubyValue(Value::NewObject(global));
		rb_define_global_const(PRODUCT_NAME, ruby_api_val);
	}
コード例 #11
0
ファイル: process.cpp プロジェクト: Val9/titanium_desktop
	KObjectRef Process::CloneEnvironment()
	{
		SharedStringList properties = environment->GetPropertyNames();
		KObjectRef clonedEnvironment = new StaticBoundObject();
		for (size_t i = 0; i < properties->size(); i++)
		{
			std::string property = *properties->at(i);
			std::string value = environment->Get(property.c_str())->ToString();
			clonedEnvironment->Set(property.c_str(), Value::NewString(value.c_str()));
		}
		return clonedEnvironment;
	}
コード例 #12
0
ファイル: php_evaluator.cpp プロジェクト: mital/kroll
	static string GetContextId(KObjectRef global)
	{
		string contextId(global->GetString("__php_module_id__"));
		if (contextId.empty())
		{
			static int nextId = 0;
			contextId.append("__kroll__namespace__");
			contextId.append(KList::IntToChars(++nextId));
			global->SetString("__php_module_id__", contextId);
		}

		return contextId;
	}
コード例 #13
0
 void PlatformModule::Start()
 {
     // Duplicate the network module address, macaddress and interfaces here for
     // backward compatibility. The network module should be initialized when
     // Start() is called.
     if (!GlobalObject::GetInstance()->GetObject("Network").isNull())
     {
         KObjectRef network = GlobalObject::GetInstance()->GetObject("Network");
         this->binding->Set("getAddress", network->Get("getAddress"));
         this->binding->Set("getMACAddress", network->Get("getMACAddress"));
         this->binding->Set("getInterfaces", network->Get("getInterfaces"));
     }
 }
コード例 #14
0
ファイル: process.cpp プロジェクト: Val9/titanium_desktop
	/*static*/
	KObjectRef Process::GetCurrentEnvironment()
	{
		KObjectRef kenv = new StaticBoundObject();
		std::map<std::string, std::string> env = EnvironmentUtils::GetEnvironment();

		std::map<std::string, std::string>::iterator i = env.begin();
		while (i != env.end())
		{
			kenv->SetString(i->first.c_str(), i->second.c_str());
			i++;
		}
		return kenv;
	}
コード例 #15
0
 void HttpServerRequest::GetHeaders(const ValueList& args, KValueRef result)
 {
     Poco::Net::HTTPServerRequest::ConstIterator iter = request.begin();
     KObjectRef headers = new StaticBoundObject();
     
     for(; iter != request.end(); iter++)
     {
         std::string name = iter->first;
         std::string value = iter->second;
         headers->SetString(name.c_str(), value.c_str());
     }
     result->SetObject(headers);
 }
コード例 #16
0
ファイル: php_module.cpp プロジェクト: toisoftware/TideSDK
void PHPModule::Stop()
{
    PHPModule::instance_ = NULL;

    KObjectRef global = this->host->GetGlobalObject();
    Script::GetInstance()->RemoveScriptEvaluator(this->binding);
    global->Set("PHP", Value::Undefined);
    this->binding->Set("evaluate", Value::Undefined);

    this->binding = 0;
    PHPModule::instance_ = 0;

    php_embed_shutdown(TSRMLS_C);
}
コード例 #17
0
 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);
 }
コード例 #18
0
KValueRef ScopeMethodDelegate::Call(const ValueList& args)
{
	std::string key = args.at(0)->ToString();
	KObjectRef obj = IsGlobalKey(key) ? global : scope;
	if (type == GET)
	{
		// not found, look inside scope
		return obj->Get(key.c_str());
	}
	else
	{
		KValueRef result = args.at(1);
		obj->SetNS(key.c_str(),result);
		return Value::Undefined;
	}
}
コード例 #19
0
    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;
    }
コード例 #20
0
	bool ProfiledBoundObject::Equals(KObjectRef other)
	{
		AutoPtr<ProfiledBoundObject> pother = other.cast<ProfiledBoundObject>();
		if (!pother.isNull())
			other = pother->GetDelegate();

		return other.get() == this->GetDelegate().get();
	}
コード例 #21
0
	void UIBinding::Log(Logger::Level level, std::string& message)
	{
		if (level > Logger::LWARN)
			return;

		std::string methodName("warn");
		if (level < Logger::LWARN)
			methodName = "error";

		std::string origMethodName(methodName);
		origMethodName.append("_orig");

		std::vector<AutoUserWindow>& openWindows = UIBinding::GetInstance()->GetOpenWindows();
		for (size_t i = 0; i < openWindows.size(); i++)
		{
			KObjectRef domWindow = openWindows[i]->GetDOMWindow();
			if (domWindow.isNull())
				continue;

			KObjectRef console = domWindow->GetObject("console", 0);
			if (console.isNull())
				continue;

			KMethodRef method = console->GetMethod(origMethodName.c_str(), 0);
			if (method.isNull())
				method = console->GetMethod(methodName.c_str(), 0);

			RunOnMainThread(method, ValueList(Value::NewString(message)), false);
		}
	}
コード例 #22
0
	void UIBinding::_SetMenu(const ValueList& args, KValueRef result)
	{
		args.VerifyException("setMenu", "o|0");
		KObjectRef argObj = args.GetObject(0, NULL);
		AutoMenu menu = NULL;

		if (!argObj.isNull())
		{
			menu = argObj.cast<Menu>();
		}

		this->SetMenu(menu); // platform-specific impl

		// Notify all windows that the app menu has changed.
		std::vector<AutoUserWindow>::iterator i = openWindows.begin();
		while (i != openWindows.end()) {
			(*i++)->AppMenuChanged();
		}
	}
コード例 #23
0
ファイル: k_kjs_method.cpp プロジェクト: fossamikom/TideSDK
    KValueRef KKJSMethod::Call(KObjectRef thisObject, const ValueList& args)
    {
        JSValueRef thisObjectValue = KJSUtil::ToJSValue(Value::NewObject(thisObject), this->context);
        if (!JSValueIsObject(this->context, thisObjectValue))
        {
            SharedString ss(thisObject->DisplayString());
            throw ValueException::FromFormat("Could not convert %s to JSObjectRef for KKJSMethod::Call",
                ss->c_str());
        }

        JSObjectRef jsThisObject = JSValueToObject(this->context, thisObjectValue, NULL);
        if (!jsThisObject)
        {
            SharedString ss(thisObject->DisplayString());
            throw ValueException::FromFormat("Could not convert %s to JSObjectRef for KKJSMethod::Call",
                ss->c_str());
        }

        return this->Call(jsThisObject, args);
    }
コード例 #24
0
    void RubyEvaluator::ContextToGlobal(VALUE ctx, KObjectRef o)
    {
        if (global_object.isNull())
            return;

        // Next copy all methods over -- they override variables
        VALUE methods = rb_funcall(ctx, rb_intern("singleton_methods"), 0);
        for (long i = 0; i < RARRAY_LEN(methods); i++)
        {
            VALUE meth_symbol = rb_ary_entry(methods, i);
            const char* meth_name = STR2CSTR(meth_symbol);

            // Skip our special method_missing method
            if (strcmp(meth_name, "method_missing") == 0)
                continue;

            volatile VALUE rmeth = rb_funcall(ctx, rb_intern("method"), 1, meth_symbol);
            KMethodRef method = new KRubyMethod(rmeth, meth_name);
            o->SetMethod(meth_name, method);
        }
    }
コード例 #25
0
ファイル: Network.cpp プロジェクト: finglish/titanium_desktop
void Network::_GetHostByAddress(const ValueList& args, KValueRef result)
{
    if (args.at(0)->IsObject())
    {
        KObjectRef obj = args.at(0)->ToObject();
        AutoPtr<IPAddress> b = obj.cast<IPAddress>();
        if (!b.isNull())
        {
            // in this case, they've passed us an IPAddressBinding
            // object, which we can just retrieve the ipaddress
            // instance and resolving using it
            Poco::Net::IPAddress addr(b->GetAddress()->toString());
            AutoPtr<Host> binding = new Host(addr);
            if (binding->IsInvalid())
            {
                throw ValueException::FromString("Could not resolve address");
            }
            result->SetObject(binding);
            return;
        }
        else
        {
            KMethodRef toStringMethod = obj->GetMethod("toString");
            if (toStringMethod.isNull())
                throw ValueException::FromString("Unknown object passed");

            result->SetObject(GetHostBinding(toStringMethod->Call()->ToString()));
            return;
        }
    }
    else if (args.at(0)->IsString())
    {
        // in this case, they just passed in a string so resolve as normal
        result->SetObject(GetHostBinding(args.GetString(0)));
    }
}
コード例 #26
0
ファイル: window_config.cpp プロジェクト: fossamikom/TideSDK
static bool CoerceBool(KObjectRef props, const char* name, bool defaultValue)
{
	KValueRef v(props->Get(name));
	if (v->IsString())
	{
		std::string value(v->ToString());
		if (value=="yes" || value=="1" || value=="true" || value=="True")
			return true;
		else
			return false;
	}
	else if (v->IsInt())
		return v->ToInt();

	else if (v->IsBool())
		return v->ToBool();

	return defaultValue;
}
コード例 #27
0
	ProfiledBoundObject::ProfiledBoundObject(KObjectRef delegate) :
		KObject(delegate->GetType()),
		delegate(delegate),
		count(1)
	{
	}
コード例 #28
0
namespace tide
{
    RubyEvaluator::RubyEvaluator() :
        StaticBoundObject("Ruby.Evaluator")
    {
        /**
         * @notiapi(method=True,name=Ruby.canEvaluate,since=0.7)
         * @notiarg[String, mimeType] Code mime type
         * @notiresult[bool] whether or not the mimetype is understood by Ruby
         */
        SetMethod("canEvaluate", &RubyEvaluator::CanEvaluate);
        
        /**
         * @notiapi(method=Ruby,name=Ruby.evaluate,since=0.2) Evaluates a string as Ruby code
         * @notiarg[String, mimeType] Code mime type (normally "text/ruby")
         * @notiarg[String, name] name of the script source
         * @notiarg[String, code] Ruby script code
         * @notiarg[Object, scope] global variable scope
         * @notiresult[Any] result of the evaluation
         */
        SetMethod("evaluate", &RubyEvaluator::Evaluate);
    }

    RubyEvaluator::~RubyEvaluator()
    {
    }

    static KObjectRef global_object;
    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);
    }

    VALUE RubyEvaluator::GetContext(KObjectRef global)
    {
        std::string theid = this->GetContextId(global);
        VALUE ctx = rb_gv_get(theid.c_str());
        if (ctx == Qnil)
        {
            VALUE ctx_class = rb_define_class("KrollRubyContext", rb_cObject);
            rb_define_method(ctx_class, "method_missing", VALUEFUNC(m_missing), -1); 
            ctx = rb_obj_alloc(ctx_class);
            rb_gv_set(theid.c_str(), ctx);
        }
        return ctx;
    }

    VALUE reval_do_call(VALUE args)
    {
        // Don't use rb_obj_instance_eval here, as it will implicitly
        // use any Ruby code block that was passed. See:
        // http://banisterfiend.wordpress.com/2008/09/25/metaprogramming-in-the-ruby-c-api-part-one-blocks/
        VALUE ctx = rb_ary_shift(args);
        VALUE code = rb_ary_shift(args);
        return rb_funcall(ctx, rb_intern("instance_eval"), 1, code);
    }
    
    void RubyEvaluator::CanEvaluate(const ValueList& args, KValueRef result)
    {
        args.VerifyException("canEvaluate", "s");
        std::string mimeType = args.GetString(0);
        result->SetBool(mimeType == "text/ruby");
    }

    void RubyEvaluator::Evaluate(const ValueList& args, KValueRef result)
    {
        args.VerifyException("evaluate", "s s s o");
        
        //const char *mimeType = args.GetString(0).c_str();
        std::string name = args.GetString(1);
        std::string code = args.GetString(2);
        global_object = args.GetObject(3);

        VALUE ctx = this->GetContext(global_object);

        VALUE rargs = rb_ary_new();
        rb_ary_push(rargs, ctx);
        rb_ary_push(rargs, rb_str_new2(code.c_str()));

        int error;
        VALUE returnValue = rb_protect(reval_do_call, rargs, &error);
        RubyEvaluator::ContextToGlobal(ctx, global_object);

        if (error != 0)
        {
            std::string error("An error occured while parsing Ruby (");
            error += name;
            error += "): ";

            // Display a stringified version of the exception.
            VALUE exception = rb_gv_get("$!");
            KValueRef v = RubyUtils::ToKrollValue(exception);
            SharedString ss = v->DisplayString();
            error.append(ss->c_str());

            // Try to make a nice backtrace for the user.
            VALUE backtrace = rb_funcall(exception,
                rb_intern("backtrace"), 0);
            VALUE rBacktraceString = rb_funcall(backtrace,
                rb_intern("join"), 1, rb_str_new2("\n"));
            if (TYPE(rBacktraceString) == T_STRING)
            {
                error.append("\n");
                error.append(StringValuePtr(rBacktraceString));
            }

            Logger *logger = Logger::Get("Ruby");
            logger->Error(error);

            result->SetUndefined();
            return;
        }

        result->SetValue(RubyUtils::ToKrollValue(returnValue));
    }

    void RubyEvaluator::ContextToGlobal(VALUE ctx, KObjectRef o)
    {
        if (global_object.isNull())
            return;

        // Next copy all methods over -- they override variables
        VALUE methods = rb_funcall(ctx, rb_intern("singleton_methods"), 0);
        for (long i = 0; i < RARRAY_LEN(methods); i++)
        {
            VALUE meth_symbol = rb_ary_entry(methods, i);
            const char* meth_name = STR2CSTR(meth_symbol);

            // Skip our special method_missing method
            if (strcmp(meth_name, "method_missing") == 0)
                continue;

            volatile VALUE rmeth = rb_funcall(ctx, rb_intern("method"), 1, meth_symbol);
            KMethodRef method = new KRubyMethod(rmeth, meth_name);
            o->SetMethod(meth_name, method);
        }
    }
}
コード例 #29
0
ファイル: kobject.cpp プロジェクト: toisoftware/TideSDK
bool KObject::Equals(KObjectRef other)
{
    return other.get() == this;
}
コード例 #30
0
	UIBinding::UIBinding(Host *host) :
		KAccessorObject("UI"),
		host(host)
	{
		instance = this;

		// @tiproperty[Number, UI.CENTERED, since=0.6] The CENTERED event constant
		this->Set("CENTERED", Value::NewInt(UIBinding::CENTERED));

		/**
		 * @tiapi(method=True,name=UI.createMenu,since=0.6)
		 * @tiapi Create a new menu
		 * @tiresult[UI.Menu] A new menu
		 */
		this->SetMethod("createMenu", &UIBinding::_CreateMenu);

		/**
		 * @tiapi(method=True,name=UI.createMenuItem,since=0.6)
		 * @tiapi Create a new menu item.
		 * @tiarg[String, label] The label for this menu item
		 * @tiarg[Function, eventListener, optional=True] An event listener for this menu item
		 * @tiarg[String, iconURL, optional=True] A URL to an icon to use for this menu item
		 * @tiresult[UI.MenuItem] A new menu item
		 */
		this->SetMethod("createMenuItem", &UIBinding::_CreateMenuItem);

		/**
		 * @tiapi(method=True,name=UI.createCheckMenuItem,since=0.6)
		 * @tiapi Create a new CheckMenuItem object.
		 * @tiarg[String, label] The label for this menu item
		 * @tiarg[Function, eventListener, optional=True] An event listener for this menu item
		 * @tiresult[UI.CheckMenuItem] The new CheckMenuItem object
		 */
		this->SetMethod("createCheckMenuItem", &UIBinding::_CreateCheckMenuItem);

		/**
		 * @tiapi(method=True,name=UI.createSeperatorMenuItem,since=0.6)
		 * @tiapi Create a new separator menu item.
		 * @tiresult[UI.SeparatorMenuItem] A new separator menu item
		 */
		this->SetMethod("createSeparatorMenuItem", &UIBinding::_CreateSeparatorMenuItem);

		/**
		 * @tiapi(method=True,name=UI.setMenu,since=0.2) Set a menu for the application
		 * @tiarg[UI.Menu|null, menu] A Menu object to use as the menu or null to unset the menu
		 */
		this->SetMethod("setMenu", &UIBinding::_SetMenu);

		/**
		 * @tiapi(method=True,name=UI.getMenu,since=0.2) Returns the application's main MenuItem
		 * @tiresult[UI.Menu|null] The application's main menu
		 */
		this->SetMethod("getMenu", &UIBinding::_GetMenu);

		/**
		 * @tiapi(method=True,name=UI.setContextMenu,since=0.2) Set the application's context menu
		 * @tiarg(for=UI.setContextMenu,type=UI.Menu|null,name=menu) a MenuItem object or null to unset
		 */
		this->SetMethod("setContextMenu", &UIBinding::_SetContextMenu);

		/**
		 * @tiapi(method=True,name=UI.getContextMenu,since=0.2) Returns the application context menu
		 * @tiresult(for=UI.getContextMenu,type=UI.Menu|null) the application's context MenuItem object
		 */
		this->SetMethod("getContextMenu", &UIBinding::_GetContextMenu);

		/**
		 * @tiapi(method=True,name=UI.setIcon,since=0.2) Set the application's icon
		 * @tiarg(for=UI.setIcon,type=String,name=menu) path to the icon
		 */
		this->SetMethod("setIcon", &UIBinding::_SetIcon);

		/**
		 * @tiapi(method=True,name=UI.addTray,since=0.2)
		 * @tiapi Create and add a tray icon
		 * @tiarg[String, iconURL] URL to the icon to use for this tray item
		 * @tiarg[Function, eventListener, optional=True] Event listener to add for this item
		 * @tiresult(for=UI.addTray,type=UI.Tray|null) the application's Tray icon object
		 */
		this->SetMethod("addTray", &UIBinding::_AddTray);

		/**
		 * @tiapi(method=True,name=UI.clearTray,since=0.2)
		 * @tiapi Empty the tray of all this application's tray items
		 */
		this->SetMethod("clearTray", &UIBinding::_ClearTray);

		/**
		 * @tiapi(method=True,name=UI.setDockIcon,since=0.2) Set the dock icon
		 * @tiarg(for=UI.setDockIcon,type=String,name=icon) path to the icon
		 */
		this->SetMethod("setDockIcon", &UIBinding::_SetDockIcon);

		/**
		 * @tiapi(method=True,name=UI.setDockMenu,since=0.2) Set the dock menu
		 * @tiarg(for=UI.setDockMenu,type=UI.Menu,name=menu) The new menu for the dock
		 */
		this->SetMethod("setDockMenu", &UIBinding::_SetDockMenu);

		/**
		 * @tiapi(method=True,name=UI.setBadge,since=0.2,platforms=osx)
		 * @tiapi Set the application icon's badge text.
		 * @tiarg[String, text] The new badge text.
		 */
		this->SetMethod("setBadge", &UIBinding::_SetBadge);

		/**
		 * @tiapi(method=True,name=UI.setBadgeImage,since=0.2,platforms=osx)
		 * @tiapi Set the application icon's badge image.
		 * @tiarg[String, imageURL] URL to the new badge image.
		 */
		this->SetMethod("setBadgeImage", &UIBinding::_SetBadgeImage);

		/**
		 * @tiapi(method=True,name=UI.getIdleTime,since=0.2)
		 * @tiapi Returns the user's idle time (for the desktop, not just the application)
		 * @tiresult(for=UI.getIdleTime,type=Number) Number of milliseconds of idle time.
		 */
		this->SetMethod("getIdleTime", &UIBinding::_GetIdleTime);

		/**
		 * @tiapi(method=True,name=UI.getOpenWindows,version=0.4) Returns the list of currently open windows
		 * @tiresult(for=UI.getOpenWindows,type=Array<UI.UserWindow>) the list of open windows
		 */
		/**
		 * @tiapi(method=True,name=UI.getWindows,version=0.4) Returns the list of currently open windows
		 * @tiresult(for=UI.getWindows,type=Array<UI.UserWindow>) the list of open windows
		 */
		this->SetMethod("getOpenWindows", &UIBinding::_GetOpenWindows);
		this->SetMethod("getWindows", &UIBinding::_GetOpenWindows);

		/**
		 * @tiapi(method=True,name=UI.getMainWindow,since=0.6)
		 * @tiapi Return the application's main window
		 * @tiresult[UI.UserWindow] The main window for this application
		 */
		this->SetMethod("getMainWindow", &UIBinding::_GetMainWindow);

		this->Set("Clipboard", Value::NewObject(new Clipboard()));

		KObjectRef global = host->GetGlobalObject();
		KValueRef ui_binding_val = Value::NewObject(this);
		global->Set("UI", ui_binding_val);

		Logger::AddLoggerCallback(&UIBinding::Log);
	}