Var JsBuiltInEngineInterfaceExtensionObject::EntryJsBuiltIn_RegisterChakraLibraryFunction(RecyclableObject* function, CallInfo callInfo, ...)
    {
        EngineInterfaceObject_CommonFunctionProlog(function, callInfo);

        AssertOrFailFast(args.Info.Count >= 3 && JavascriptString::Is(args.Values[1]) && JavascriptFunction::Is(args.Values[2]));

        JavascriptLibrary * library = scriptContext->GetLibrary();

        // retrieves arguments
        JavascriptString* methodName = JavascriptString::FromVar(args.Values[1]);
        JavascriptFunction* func = JavascriptFunction::FromVar(args.Values[2]);

        // Set the function's display name, as the function we pass in argument are anonym.
        func->GetFunctionProxy()->SetIsPublicLibraryCode();
        func->GetFunctionProxy()->EnsureDeserialized()->SetDisplayName(methodName->GetString(), methodName->GetLength(), 0);

        DynamicObject* chakraLibraryObject = GetPrototypeFromName(PropertyIds::__chakraLibrary, scriptContext);
        PropertyIds functionIdentifier = JavascriptOperators::GetPropertyId(methodName, scriptContext);

        // Link the function to __chakraLibrary.
        ScriptFunction* scriptFunction = library->CreateScriptFunction(func->GetFunctionProxy());
        scriptFunction->GetFunctionProxy()->SetIsJsBuiltInCode();

        Assert(scriptFunction->HasFunctionBody());
        scriptFunction->GetFunctionBody()->SetJsBuiltInForceInline();

        scriptFunction->SetPropertyWithAttributes(PropertyIds::name, methodName, PropertyConfigurable, nullptr);

        library->AddMember(chakraLibraryObject, functionIdentifier, scriptFunction);

        //Don't need to return anything
        return library->GetUndefined();
    }
Пример #2
0
		// Restores renderer's state (game map, fog color)
		// after returning from the game client.
		void StartupScreen::RestoreRenderer() {
			ScopedPrivilegeEscalation privilege;
			static ScriptFunction func("StartupScreenUI", "void SetupRenderer()");
			ScriptContextHandle c = func.Prepare();
			c->SetObject(&*ui);
			c.ExecuteChecked();
		}
Пример #3
0
		ClientUI::ClientUI(client::IRenderer *r, client::IAudioDevice *a, IFont *font, Client *client) :
		renderer(r),
		audioDevice(a),
		font(font),client(client){
			SPADES_MARK_FUNCTION();
			if(r == NULL)
				SPInvalidArgument("r");
			if(a == NULL)
				SPInvalidArgument("a");
			
			helper.Set(new ClientUIHelper(this), false);
			
			static ScriptFunction uiFactory("ClientUI@ CreateClientUI(Renderer@, AudioDevice@, Font@, ClientUIHelper@)");
			{
				ScriptContextHandle ctx = uiFactory.Prepare();
				ctx->SetArgObject(0, renderer);
				ctx->SetArgObject(1, audioDevice);
				ctx->SetArgObject(2, font);
				ctx->SetArgObject(3, &*helper);
				
				ctx.ExecuteChecked();
				ui = reinterpret_cast<asIScriptObject *>(ctx->GetReturnObject());
			}
			
		}
Пример #4
0
		void ClientUI::RunFrame(float dt) {
			SPADES_MARK_FUNCTION();
			static ScriptFunction func("ClientUI", "void RunFrame(float)");
			ScriptContextHandle c = func.Prepare();
			c->SetObject(&*ui);
			c->SetArgFloat(0, dt);
			c.ExecuteChecked();
		}
ScriptFunction*	ScriptFunction::Stream( std::istream& in )
{
	char csft;
	in.read( reinterpret_cast<char*>(&csft), sizeof(csft) );
	ScriptFunction* sf = ScriptFunction::Factory( static_cast<ScriptFunctionType>(csft) );
	if ( sf )
		sf->StreamIn( in );
	return sf;
}
Пример #6
0
void ScriptFunction::callCallback(
    const v8::FunctionCallbackInfo<v8::Value>& args) {
  ASSERT(args.Data()->IsExternal());
  ScriptFunction* scriptFunction = static_cast<ScriptFunction*>(
      v8::Local<v8::External>::Cast(args.Data())->Value());
  ScriptValue result = scriptFunction->call(
      ScriptValue(scriptFunction->getScriptState(), args[0]));
  v8SetReturnValue(args, result.v8Value());
}
Пример #7
0
		void ClientUI::CloseUI() {
			SPADES_MARK_FUNCTION();
			if(!ui){
				return;
			}
			static ScriptFunction func("ClientUI", "void CloseUI()");
			ScriptContextHandle c = func.Prepare();
			c->SetObject(&*ui);
			c.ExecuteChecked();
		}
Пример #8
0
		void StartupScreen::RunFrame(float dt) {
			SPADES_MARK_FUNCTION();

			ScopedPrivilegeEscalation privilege;
			static ScriptFunction func("StartupScreenUI", "void RunFrame(float)");
			ScriptContextHandle c = func.Prepare();
			c->SetObject(&*ui);
			c->SetArgFloat(0, dt);
			c.ExecuteChecked();
		}
Пример #9
0
		bool ClientUI::NeedsInput() {
			SPADES_MARK_FUNCTION();
			if(!ui){
				return false;
			}
			static ScriptFunction func("ClientUI", "bool NeedsInput()");
			ScriptContextHandle c = func.Prepare();
			c->SetObject(&*ui);
			c.ExecuteChecked();
			return c->GetReturnByte() != 0;
		}
Пример #10
0
		AABB2 ClientUI::GetTextInputRect() {
			SPADES_MARK_FUNCTION();
			if(!ui){
				return AABB2();
			}
			static ScriptFunction func("ClientUI", "AABB2 GetTextInputRect()");
			ScriptContextHandle c = func.Prepare();
			c->SetObject(&*ui);
			c.ExecuteChecked();
			return *reinterpret_cast<AABB2*>(c->GetReturnObject());
		}
Пример #11
0
		bool MainScreen::WantsToBeClosed() {
			SPADES_MARK_FUNCTION();
			if(!ui){
				return false;
			}
			static ScriptFunction func("MainScreenUI", "bool WantsToBeClosed()");
			ScriptContextHandle c = func.Prepare();
			c->SetObject(&*ui);
			c.ExecuteChecked();
			return c->GetReturnByte() != 0;
		}
Пример #12
0
void ScriptFunction::callCallback(const v8::FunctionCallbackInfo<v8::Value>& args)
{
    v8::Isolate* isolate = args.GetIsolate();
    ASSERT(!args.Data().IsEmpty());
    ScriptFunction* function = ScriptFunction::Cast(args.Data());
    v8::Local<v8::Value> value = args.Length() > 0 ? args[0] : v8::Local<v8::Value>(v8::Undefined(isolate));

    ScriptValue result = function->call(ScriptValue(ScriptState::current(isolate), value));

    v8SetReturnValue(args, result.v8Value());
}
Пример #13
0
		bool StartupScreen::WantsToBeClosed() {
			SPADES_MARK_FUNCTION();
			if (!ui) {
				return false;
			}
			ScopedPrivilegeEscalation privilege;
			static ScriptFunction func("StartupScreenUI", "bool WantsToBeClosed()");
			ScriptContextHandle c = func.Prepare();
			c->SetObject(&*ui);
			c.ExecuteChecked();
			return c->GetReturnByte() != 0;
		}
Пример #14
0
		AABB2 StartupScreen::GetTextInputRect() {
			SPADES_MARK_FUNCTION();
			if (!ui) {
				return AABB2();
			}
			ScopedPrivilegeEscalation privilege;
			static ScriptFunction func("StartupScreenUI", "AABB2 GetTextInputRect()");
			ScriptContextHandle c = func.Prepare();
			c->SetObject(&*ui);
			c.ExecuteChecked();
			return *reinterpret_cast<AABB2 *>(c->GetReturnObject());
		}
Пример #15
0
		void StartupScreen::Closing() {
			SPADES_MARK_FUNCTION();

			if (!ui) {
				return;
			}
			ScopedPrivilegeEscalation privilege;
			static ScriptFunction func("StartupScreenUI", "void Closing()");
			ScriptContextHandle c = func.Prepare();
			c->SetObject(&*ui);
			c.ExecuteChecked();
		}
Пример #16
0
		void ClientUI::TextInputEvent(const std::string &ch) {
			SPADES_MARK_FUNCTION();
			if(!ui){
				return;
			}
			static ScriptFunction func("ClientUI", "void TextInputEvent(string)");
			ScriptContextHandle c = func.Prepare();
			std::string k = ch;
			c->SetObject(&*ui);
			c->SetArgObject(0, reinterpret_cast<void*>(&k));
			c.ExecuteChecked();
		}
Пример #17
0
		void ClientUI::WheelEvent(float x, float y) {
			SPADES_MARK_FUNCTION();
			if(!ui){
				return;
			}
			
			static ScriptFunction func("ClientUI", "void WheelEvent(float, float)");
			ScriptContextHandle c = func.Prepare();
			c->SetObject(&*ui);
			c->SetArgFloat(0, x);
			c->SetArgFloat(1, y);
			c.ExecuteChecked();
		}
Пример #18
0
ScriptFunction *ScriptInterpreter::loadFunction(uint32 index) {
	//GONE WHILE DEBUGGING assert(index < _functions.size());
	if (index >= _functions.size()) return NULL;
	ScriptFunction *scriptFunction;
	scriptFunction = _functions[index]->func;
	if (!scriptFunction) {
		scriptFunction = new ScriptFunction(this);
		_scriptFile->seek(_functions[index]->offset);
		scriptFunction->load(_scriptFile);
		_functions[index]->func = scriptFunction;
	}
	return scriptFunction;
}
Пример #19
0
		void StartupScreen::TextInputEvent(const std::string &ch) {
			SPADES_MARK_FUNCTION();
			if (!ui) {
				return;
			}
			ScopedPrivilegeEscalation privilege;
			static ScriptFunction func("StartupScreenUI", "void TextInputEvent(string)");
			ScriptContextHandle c = func.Prepare();
			std::string k = ch;
			c->SetObject(&*ui);
			c->SetArgObject(0, reinterpret_cast<void *>(&k));
			c.ExecuteChecked();
		}
Пример #20
0
		void ClientUI::KeyEvent(const std::string & key, bool down) {
			SPADES_MARK_FUNCTION();
			if(!ui){
				return;
			}
			static ScriptFunction func("ClientUI", "void KeyEvent(string, bool)");
			ScriptContextHandle c = func.Prepare();
			std::string k = key;
			c->SetObject(&*ui);
			c->SetArgObject(0, reinterpret_cast<void*>(&k));
			c->SetArgByte(1, down ? 1 : 0);
			c.ExecuteChecked();
		}
Пример #21
0
		void StartupScreen::WheelEvent(float x, float y) {
			SPADES_MARK_FUNCTION();
			if (!ui) {
				return;
			}

			ScopedPrivilegeEscalation privilege;
			static ScriptFunction func("StartupScreenUI", "void WheelEvent(float, float)");
			ScriptContextHandle c = func.Prepare();
			c->SetObject(&*ui);
			c->SetArgFloat(0, x);
			c->SetArgFloat(1, y);
			c.ExecuteChecked();
		}
Пример #22
0
		bool MainScreen::AcceptsTextInput() {
			SPADES_MARK_FUNCTION();
			if(subview){
				return subview->AcceptsTextInput();
			}
			if(!ui){
				return false;
			}
			static ScriptFunction func("MainScreenUI", "bool AcceptsTextInput()");
			ScriptContextHandle c = func.Prepare();
			c->SetObject(&*ui);
			c.ExecuteChecked();
			return c->GetReturnByte() != 0;
		}
Пример #23
0
		void ClientUI::RecordChatLog(const std::string &msg,
									 Vector4 color) {
			SPADES_MARK_FUNCTION();
			if(!ui){
				return;
			}
			static ScriptFunction func("ClientUI", "void RecordChatLog(string, Vector4)");
			ScriptContextHandle c = func.Prepare();
			std::string k = msg;
			c->SetObject(&*ui);
			c->SetArgObject(0, reinterpret_cast<void*>(&k));
			c->SetArgObject(1, reinterpret_cast<void*>(&color));
			c.ExecuteChecked();
		}
Пример #24
0
		void ClientUI::TextEditingEvent(const std::string &ch,
										int start, int len) {
			SPADES_MARK_FUNCTION();
			if(!ui){
				return;
			}
			static ScriptFunction func("ClientUI", "void TextEditingEvent(string,int,int)");
			ScriptContextHandle c = func.Prepare();
			std::string k = ch;
			c->SetObject(&*ui);
			c->SetArgObject(0, reinterpret_cast<void*>(&k));
			c->SetArgDWord(1, static_cast<asDWORD>(start));
			c->SetArgDWord(2, static_cast<asDWORD>(len));
			c.ExecuteChecked();
		}
Пример #25
0
		void MainScreen::Closing() {
			SPADES_MARK_FUNCTION();
			if(subview){
				subview->Closing();
				subview = NULL;
			}
			
			if(!ui){
				return;
			}
			static ScriptFunction func("MainScreenUI", "void Closing()");
			ScriptContextHandle c = func.Prepare();
			c->SetObject(&*ui);
			c.ExecuteChecked();
		}
Пример #26
0
void OnsetDetector::onOnset(ScriptFunction &handler)
{
    if(handler.getNumargs() != 2) {
        throw std::logic_error("onOnset handler should take one argument");
    }
    onOnsetHandler.store(new ScriptFunction(handler));
}
Пример #27
0
		void StartupScreen::DoInit() {
			SPADES_MARK_FUNCTION();

			ScopedPrivilegeEscalation privilege;
			static ScriptFunction uiFactory("StartupScreenUI@ CreateStartupScreenUI(Renderer@, "
			                                "AudioDevice@, FontManager@, StartupScreenHelper@)");
			{
				ScriptContextHandle ctx = uiFactory.Prepare();
				ctx->SetArgObject(0, renderer);
				ctx->SetArgObject(1, audioDevice);
				ctx->SetArgObject(2, fontManager);
				ctx->SetArgObject(3, &*helper);

				ctx.ExecuteChecked();
				ui = reinterpret_cast<asIScriptObject *>(ctx->GetReturnObject());
			}
		}
Пример #28
0
		void MainScreen::WheelEvent(float x, float y) {
			SPADES_MARK_FUNCTION();
			if(subview){
				subview->WheelEvent(x, y);
				return;
			}
			if(!ui){
				return;
			}
			
			static ScriptFunction func("MainScreenUI", "void WheelEvent(float, float)");
			ScriptContextHandle c = func.Prepare();
			c->SetObject(&*ui);
			c->SetArgFloat(0, x);
			c->SetArgFloat(1, y);
			c.ExecuteChecked();
		}
Пример #29
0
		void MainScreen::DoInit() {
			SPADES_MARK_FUNCTION();
			renderer->Init();
			
			static ScriptFunction uiFactory("MainScreenUI@ CreateMainScreenUI(Renderer@, AudioDevice@, Font@, MainScreenHelper@)");
			{
				ScriptContextHandle ctx = uiFactory.Prepare();
				ctx->SetArgObject(0, renderer);
				ctx->SetArgObject(1, audioDevice);
				ctx->SetArgObject(2, font);
				ctx->SetArgObject(3, &*helper);
				
				ctx.ExecuteChecked();
				ui = reinterpret_cast<asIScriptObject *>(ctx->GetReturnObject());
			}

		}
Пример #30
0
		void MainScreen::RunFrame(float dt) {
			SPADES_MARK_FUNCTION();
			if(subview){
				try{
					subview->RunFrame(dt);
					if(subview->WantsToBeClosed()) {
						subview->Closing();
						subview = NULL;
						RestoreRenderer();
					}else{
						return;
					}
				}catch(const std::exception& ex) {
					SPLog("[!] Error while running a game client: %s", ex.what());
					subview->Closing();
					subview = NULL;
					RestoreRenderer();
					helper->errorMessage = ex.what();
				}
			}
			if(timeToStartInitialization > 100.f){
				timeToStartInitialization = 0.2f;
			}
			if(timeToStartInitialization > 0.f){
				DrawStartupScreen();
				timeToStartInitialization -= dt;
				if(timeToStartInitialization <= 0.f){
					// do init
					DoInit();
				}
				return;
			}
			
			static ScriptFunction func("MainScreenUI", "void RunFrame(float)");
			ScriptContextHandle c = func.Prepare();
			c->SetObject(&*ui);
			c->SetArgFloat(0, dt);
			c.ExecuteChecked();
		}