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(); }
// 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(); }
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()); } }
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; }
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()); }
void ClientUI::CloseUI() { SPADES_MARK_FUNCTION(); if(!ui){ return; } static ScriptFunction func("ClientUI", "void CloseUI()"); ScriptContextHandle c = func.Prepare(); c->SetObject(&*ui); c.ExecuteChecked(); }
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(); }
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; }
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()); }
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; }
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()); }
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; }
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()); }
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(); }
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(); }
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(); }
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; }
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(); }
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(); }
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(); }
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; }
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(); }
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(); }
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(); }
void OnsetDetector::onOnset(ScriptFunction &handler) { if(handler.getNumargs() != 2) { throw std::logic_error("onOnset handler should take one argument"); } onOnsetHandler.store(new ScriptFunction(handler)); }
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()); } }
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(); }
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()); } }
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(); }