这篇教程C++ rq函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中rq函数的典型用法代码示例。如果您正苦于以下问题:C++ rq函数的具体用法?C++ rq怎么用?C++ rq使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了rq函数的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: GetScriptInterfacevoid CSimulation2::LoadPlayerSettings(bool newPlayers){ JSContext* cx = GetScriptInterface().GetContext(); JSAutoRequest rq(cx); JS::RootedValue global(cx, GetScriptInterface().GetGlobalObject()); GetScriptInterface().CallFunctionVoid(global, "LoadPlayerSettings", m->m_MapSettings, newPlayers);}
开发者ID:JoshuaBelden,项目名称:0ad,代码行数:7,
示例2: rqvoid CComponentTypeScript::Deserialize(const CParamNode& paramNode, IDeserializer& deserialize, entity_id_t ent){ JSContext* cx = m_ScriptInterface.GetContext(); JSAutoRequest rq(cx); m_ScriptInterface.SetProperty(m_Instance, "entity", (int)ent, true, false); m_ScriptInterface.SetProperty(m_Instance, "template", paramNode, true, false); // Support a custom "Deserialize" function, to which we pass the deserialized data // instead of automatically adding the deserialized properties onto the object if (m_HasCustomDeserialize) { JS::RootedValue val(cx); // If Serialize = null, we'll still call Deserialize but with undefined argument if (!m_HasNullSerialize) deserialize.ScriptVal("object", &val); if (!m_ScriptInterface.CallFunctionVoid(m_Instance, "Deserialize", val)) LOGERROR("Script Deserialize call failed"); } else { if (!m_HasNullSerialize) { // Use ScriptObjectAppend so we don't lose the carefully-constructed // prototype/parent of this object deserialize.ScriptObjectAppend("object", m_Instance); } }}
开发者ID:Gavinator98,项目名称:0ad,代码行数:31,
示例3: rqvoid CBinarySerializerScriptImpl::ScriptString(const char* name, JS::HandleString string){ JSContext* cx = m_ScriptInterface.GetContext(); JSAutoRequest rq(cx);#if BYTE_ORDER != LITTLE_ENDIAN#error TODO: probably need to convert JS strings to little-endian#endif size_t length; JS::AutoCheckCannotGC nogc; // Serialize strings directly as UTF-16 or Latin1, to avoid expensive encoding conversions bool isLatin1 = JS_StringHasLatin1Chars(string); m_Serializer.Bool("isLatin1", isLatin1); if (isLatin1) { const JS::Latin1Char* chars = JS_GetLatin1StringCharsAndLength(cx, nogc, string, &length); if (!chars) throw PSERROR_Serialize_ScriptError("JS_GetLatin1StringCharsAndLength failed"); m_Serializer.NumberU32_Unbounded("string length", (u32)length); m_Serializer.RawBytes(name, (const u8*)chars, length); } else { const char16_t* chars = JS_GetTwoByteStringCharsAndLength(cx, nogc, string, &length); if (!chars) throw PSERROR_Serialize_ScriptError("JS_GetTwoByteStringCharsAndLength failed"); m_Serializer.NumberU32_Unbounded("string length", (u32)length); m_Serializer.RawBytes(name, (const u8*)chars, length*2); }}
开发者ID:2asoft,项目名称:0ad,代码行数:32,
示例4: rqvoid CStdDeserializer::ScriptString(const char* name, JS::MutableHandleString out){#if BYTE_ORDER != LITTLE_ENDIAN#error TODO: probably need to convert JS strings from little-endian#endif JSContext* cx = m_ScriptInterface.GetContext(); JSAutoRequest rq(cx); bool isLatin1; Bool("isLatin1", isLatin1); if (isLatin1) { std::vector<JS::Latin1Char> str; ReadStringLatin1(name, str); out.set(JS_NewStringCopyN(cx, (const char*)str.data(), str.size())); if (!out) throw PSERROR_Deserialize_ScriptError("JS_NewStringCopyN failed"); } else { utf16string str; ReadStringUTF16(name, str); out.set(JS_NewUCStringCopyN(cx, (const char16_t*)str.data(), str.length())); if (!out) throw PSERROR_Deserialize_ScriptError("JS_NewUCStringCopyN failed"); }}
开发者ID:2asoft,项目名称:0ad,代码行数:30,
示例5: LOGDvoid CBackupDeleter::run(){ if (! _ctx._options->_removeNonExistingFiles ) return; LOGD("{} START", __PRETTY_FUNCTION__); const CAsset * pRoot( _parser.getRoot() ); assert( pRoot ); CRequest rq(_ctx._options->_curlVerbose); for (const auto & p : _remote.paths()) { const CAsset * pLocal = pRoot->find(p); if (pLocal == nullptr) { rq.addHeader("X-Auth-Token", _ctx._cr.token()); const std::string url= fmt::format("{}/{}/{}", _ctx._cr.endpoint(), _ctx._options->_dstContainer, (_ctx._options->_dstFolder / rq.escapePath(p)).string() ); LOGI("deleting backup '{}'", url); //p.string()); rq.del(url); if ( rq.getHttpResponseCode() != 204 ) { LOGE("Failed to delete '{}' [http response : {}]", url, rq.getHttpResponseCode()); _ctx.abort(); } } if (_ctx.aborted()) break; } LOGD("{} DONE", __PRETTY_FUNCTION__);}
开发者ID:almorel,项目名称:hubic-backup,代码行数:32,
示例6: PushLocalCommand virtual void PushLocalCommand(player_id_t player, JS::HandleValue cmd) { JSContext* cx = GetSimContext().GetScriptInterface().GetContext(); JSAutoRequest rq(cx); m_LocalQueue.emplace_back(SimulationCommand(player, cx, cmd)); }
开发者ID:krichter722,项目名称:0ad,代码行数:7,
示例7: ENSUREbool CNetClient::OnGameStart(void* context, CFsmEvent* event){ ENSURE(event->GetType() == (uint)NMT_GAME_START); CNetClient* client = (CNetClient*)context; JSContext* cx = client->GetScriptInterface().GetContext(); JSAutoRequest rq(cx); // Find the player assigned to our GUID int player = -1; if (client->m_PlayerAssignments.find(client->m_GUID) != client->m_PlayerAssignments.end()) player = client->m_PlayerAssignments[client->m_GUID].m_PlayerID; client->m_ClientTurnManager = new CNetClientTurnManager( *client->m_Game->GetSimulation2(), *client, client->m_HostID, client->m_Game->GetReplayLogger()); client->m_Game->SetPlayerID(player); client->m_Game->StartGame(&client->m_GameAttributes, ""); JS::RootedValue msg(cx); client->GetScriptInterface().Eval("({'type':'start'})", &msg); client->PushGuiMessage(msg); return true;}
开发者ID:joselitofilho,项目名称:0ad,代码行数:25,
示例8: rqtemplate<> bool ScriptInterface::FromJSVal<bool>(JSContext* cx, JS::HandleValue v, bool& out){ JSAutoRequest rq(cx); WARN_IF_NOT(v.isBoolean(), v); out = JS::ToBoolean(v); return true;}
开发者ID:krichter722,项目名称:0ad,代码行数:7,
示例9: assert_kdbboolSched_context::deblock(unsigned cpu, Sched_context *crs, bool lazy_q = false){ assert_kdb(cpu_lock.test()); Sched_context *cs = rq(cpu).current_sched(); bool res = true; if (this == cs) { if (crs->dominates(this)) res = false; } else { deblock_refill(cpu); if ((EXPECT_TRUE(cs != 0) && cs->dominates(this)) || crs->dominates(this)) res = false; } if (res && lazy_q) return true; ready_enqueue(cpu); return res;}
开发者ID:decaprox,项目名称:l4re-snapshot,代码行数:26,
示例10: rqbool ScriptInterface::ParseJSON(const std::string& string_utf8, JS::MutableHandleValue out){ JSAutoRequest rq(m->m_cx); std::wstring attrsW = wstring_from_utf8(string_utf8); utf16string string(attrsW.begin(), attrsW.end()); if (JS_ParseJSON(m->m_cx, reinterpret_cast<const jschar*>(string.c_str()), (u32)string.size(), out)) return true; LOGERROR("JS_ParseJSON failed!"); if (!JS_IsExceptionPending(m->m_cx)) return false; JS::RootedValue exc(m->m_cx); if (!JS_GetPendingException(m->m_cx, &exc)) return false; JS_ClearPendingException(m->m_cx); // We expect an object of type SyntaxError if (!exc.isObject()) return false; JS::RootedValue rval(m->m_cx); JS::RootedObject excObj(m->m_cx, &exc.toObject()); if (!JS_CallFunctionName(m->m_cx, excObj, "toString", JS::HandleValueArray::empty(), &rval)) return false; std::wstring error; ScriptInterface::FromJSVal(m->m_cx, rval, error); LOGERROR("%s", utf8_from_wstring(error)); return false;}
开发者ID:Rektosauros,项目名称:0ad,代码行数:31,
示例11: m_runtimeScriptInterface_impl::ScriptInterface_impl(const char* nativeScopeName, const shared_ptr<ScriptRuntime>& runtime) : m_runtime(runtime), m_glob(runtime->m_rt), m_nativeScope(runtime->m_rt){ bool ok; m_cx = JS_NewContext(m_runtime->m_rt, STACK_CHUNK_SIZE); ENSURE(m_cx); JS_SetParallelIonCompilationEnabled(m_runtime->m_rt, true); // For GC debugging: // JS_SetGCZeal(m_cx, 2); JS_SetContextPrivate(m_cx, NULL); JS_SetErrorReporter(m_cx, ErrorReporter); JS_SetGlobalJitCompilerOption(m_runtime->m_rt, JSJITCOMPILER_ION_ENABLE, 1); JS_SetGlobalJitCompilerOption(m_runtime->m_rt, JSJITCOMPILER_BASELINE_ENABLE, 1); JS::ContextOptionsRef(m_cx).setExtraWarnings(1) .setWerror(0) .setVarObjFix(1) .setStrictMode(1); JS::CompartmentOptions opt; opt.setVersion(JSVERSION_LATEST); JSAutoRequest rq(m_cx); JS::RootedObject globalRootedVal(m_cx, JS_NewGlobalObject(m_cx, &global_class, NULL, JS::OnNewGlobalHookOption::FireOnNewGlobalHook, opt)); m_comp = JS_EnterCompartment(m_cx, globalRootedVal); ok = JS_InitStandardClasses(m_cx, globalRootedVal); ENSURE(ok); m_glob = globalRootedVal.get(); // Use the testing functions to globally enable gcPreserveCode. This brings quite a // big performance improvement. In future SpiderMonkey versions, we should probably // use the functions implemented here: https://bugzilla.mozilla.org/show_bug.cgi?id=1068697 JS::RootedObject testingFunctionsObj(m_cx, js::GetTestingFunctions(m_cx)); ENSURE(testingFunctionsObj); JS::RootedValue ret(m_cx); JS_CallFunctionName(m_cx, testingFunctionsObj, "gcPreserveCode", JS::HandleValueArray::empty(), &ret); JS_DefineProperty(m_cx, m_glob, "global", globalRootedVal, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT); m_nativeScope = JS_DefineObject(m_cx, m_glob, nativeScopeName, NULL, NULL, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT); JS_DefineFunction(m_cx, globalRootedVal, "print", ::print, 0, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT); JS_DefineFunction(m_cx, globalRootedVal, "log", ::logmsg, 1, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT); JS_DefineFunction(m_cx, globalRootedVal, "warn", ::warn, 1, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT); JS_DefineFunction(m_cx, globalRootedVal, "error", ::error, 1, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT); JS_DefineFunction(m_cx, globalRootedVal, "deepcopy", ::deepcopy, 1, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT); Register("ProfileStart", ::ProfileStart, 1); Register("ProfileStop", ::ProfileStop, 0); runtime->RegisterContext(m_cx);}
开发者ID:Rektosauros,项目名称:0ad,代码行数:60,
示例12: rqbool ScriptInterface::LoadGlobalScriptFile(const VfsPath& path){ JSAutoRequest rq(m->m_cx); JS::RootedObject global(m->m_cx, m->m_glob); if (!VfsFileExists(path)) { LOGERROR("File '%s' does not exist", path.string8()); return false; } CVFSFile file; PSRETURN ret = file.Load(g_VFS, path); if (ret != PSRETURN_OK) { LOGERROR("Failed to load file '%s': %s", path.string8(), GetErrorString(ret)); return false; } std::wstring code = wstring_from_utf8(file.DecodeUTF8()); // assume it's UTF-8 utf16string codeUtf16(code.begin(), code.end()); uint lineNo = 1; // CompileOptions does not copy the contents of the filename string pointer. // Passing a temporary string there will cause undefined behaviour, so we create a separate string to avoid the temporary. std::string filenameStr = path.string8(); JS::RootedValue rval(m->m_cx); JS::CompileOptions opts(m->m_cx); opts.setFileAndLine(filenameStr.c_str(), lineNo); return JS::Evaluate(m->m_cx, global, opts, reinterpret_cast<const char16_t*>(codeUtf16.c_str()), (uint)(codeUtf16.length()), &rval);}
开发者ID:krichter722,项目名称:0ad,代码行数:34,
示例13: PSERROR_GUI_OperationNeedsGUIObjectvoid IGUIObject::RegisterScriptHandler(const CStr& Action, const CStr& Code, CGUI* pGUI){ if(!GetGUI()) throw PSERROR_GUI_OperationNeedsGUIObject(); JSContext* cx = pGUI->GetScriptInterface()->GetContext(); JSAutoRequest rq(cx); JS::RootedValue globalVal(cx, pGUI->GetGlobalObject()); JS::RootedObject globalObj(cx, &globalVal.toObject()); const int paramCount = 1; const char* paramNames[paramCount] = { "mouse" }; // Location to report errors from CStr CodeName = GetName()+" "+Action; // Generate a unique name static int x = 0; char buf[64]; sprintf_s(buf, ARRAY_SIZE(buf), "__eventhandler%d (%s)", x++, Action.c_str()); JS::CompileOptions options(cx); options.setFileAndLine(CodeName.c_str(), 0); options.setCompileAndGo(true); JS::RootedFunction func(cx, JS_CompileFunction(cx, globalObj, buf, paramCount, paramNames, Code.c_str(), Code.length(), options)); if (!func) return; // JS will report an error message JS::RootedObject funcObj(cx, JS_GetFunctionObject(func)); SetScriptHandler(Action, funcObj);}
开发者ID:Rektosauros,项目名称:0ad,代码行数:34,
示例14: rqvoid IGUIObject::ScriptEvent(const CStr& Action){ auto it = m_ScriptHandlers.find(Action); if (it == m_ScriptHandlers.end()) return; JSContext* cx = m_pGUI->GetScriptInterface()->GetContext(); JSAutoRequest rq(cx); // Set up the 'mouse' parameter JS::RootedValue mouse(cx); m_pGUI->GetScriptInterface()->Eval("({})", &mouse); m_pGUI->GetScriptInterface()->SetProperty(mouse, "x", m_pGUI->m_MousePos.x, false); m_pGUI->GetScriptInterface()->SetProperty(mouse, "y", m_pGUI->m_MousePos.y, false); m_pGUI->GetScriptInterface()->SetProperty(mouse, "buttons", m_pGUI->m_MouseButtons, false); JS::AutoValueVector paramData(cx); paramData.append(mouse); JS::RootedObject obj(cx, GetJSObject()); JS::RootedValue handlerVal(cx, JS::ObjectValue(*it->second)); JS::RootedValue result(cx); bool ok = JS_CallFunctionValue(cx, obj, handlerVal, paramData, &result); if (!ok) { // We have no way to propagate the script exception, so just ignore it // and hope the caller checks JS_IsExceptionPending }}
开发者ID:Rektosauros,项目名称:0ad,代码行数:28,
示例15: rq// Return file contents as an array of lines. Assume file is UTF-8 encoded text.//// lines = readFileLines(filename);// filename: VFS filename (may include path)JS::Value JSI_VFS::ReadFileLines(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& filename){ JSContext* cx = pCxPrivate->pScriptInterface->GetContext(); JSAutoRequest rq(cx); // // read file // CVFSFile file; if (file.Load(g_VFS, filename) != PSRETURN_OK) return JSVAL_NULL; CStr contents = file.DecodeUTF8(); // assume it's UTF-8 // Fix CRLF line endings. (This function will only ever be used on text files.) contents.Replace("/r/n", "/n"); // // split into array of strings (one per line) // std::stringstream ss(contents); JS::RootedObject line_array(cx, JS_NewArrayObject(cx, JS::HandleValueArray::empty())); std::string line; int cur_line = 0; while (std::getline(ss, line)) { // Decode each line as UTF-8 JS::RootedValue val(cx); ScriptInterface::ToJSVal(cx, &val, CStr(line).FromUTF8()); JS_SetElement(cx, line_array, cur_line++, val); } return JS::ObjectValue(*line_array);}
开发者ID:svifylabs,项目名称:0ad,代码行数:39,
示例16: FromJSVal_vectortemplate<typename T> static bool FromJSVal_vector(JSContext* cx, JS::HandleValue v, std::vector<T>& out){ JSAutoRequest rq(cx); JS::RootedObject obj(cx); if (!v.isObject()) FAIL("Argument must be an array"); obj = &v.toObject(); if (!(JS_IsArrayObject(cx, obj) || JS_IsTypedArrayObject(obj))) FAIL("Argument must be an array"); u32 length; if (!JS_GetArrayLength(cx, obj, &length)) FAIL("Failed to get array length"); out.reserve(length); for (u32 i = 0; i < length; ++i) { JS::RootedValue el(cx); if (!JS_GetElement(cx, obj, i, &el)) FAIL("Failed to read array element"); T el2; if (!ScriptInterface::FromJSVal<T>(cx, el, el2)) return false; out.push_back(el2); } return true;}
开发者ID:krichter722,项目名称:0ad,代码行数:26,
示例17: LOGERRORbool ScriptInterface::LoadGlobalScripts(){ // Ignore this failure in tests if (!g_VFS) return false; // Load and execute *.js in the global scripts directory VfsPaths pathnames; vfs::GetPathnames(g_VFS, L"globalscripts/", L"*.js", pathnames); for (const VfsPath& path : pathnames) if (!LoadGlobalScriptFile(path)) { LOGERROR("LoadGlobalScripts: Failed to load script %s", path.string8()); return false; } JSAutoRequest rq(m->m_cx); JS::RootedValue proto(m->m_cx); JS::RootedObject global(m->m_cx, m->m_glob); if (JS_GetProperty(m->m_cx, global, "Vector2Dprototype", &proto)) m->m_ScriptValCache[CACHE_VECTOR2DPROTO] = DefPersistentRooted<JS::Value>(GetJSRuntime(), proto); if (JS_GetProperty(m->m_cx, global, "Vector3Dprototype", &proto)) m->m_ScriptValCache[CACHE_VECTOR3DPROTO] = DefPersistentRooted<JS::Value>(GetJSRuntime(), proto); return true;}
开发者ID:Rektosauros,项目名称:0ad,代码行数:25,
示例18: rqIComponent* CComponentManager::ConstructComponent(CEntityHandle ent, ComponentTypeId cid){ JSContext* cx = m_ScriptInterface.GetContext(); JSAutoRequest rq(cx); std::map<ComponentTypeId, ComponentType>::const_iterator it = m_ComponentTypesById.find(cid); if (it == m_ComponentTypesById.end()) { LOGERROR("Invalid component id %d", cid); return NULL; } const ComponentType& ct = it->second; ENSURE((size_t)ct.iid < m_ComponentsByInterface.size()); boost::unordered_map<entity_id_t, IComponent*>& emap1 = m_ComponentsByInterface[ct.iid]; if (emap1.find(ent.GetId()) != emap1.end()) { LOGERROR("Multiple components for interface %d", ct.iid); return NULL; } std::map<entity_id_t, IComponent*>& emap2 = m_ComponentsByTypeId[cid]; // If this is a scripted component, construct the appropriate JS object first JS::RootedValue obj(cx); if (ct.type == CT_Script) { m_ScriptInterface.CallConstructor(ct.ctor.get(), JS::HandleValueArray::empty(), &obj); if (obj.isNull()) { LOGERROR("Script component constructor failed"); return NULL; } } // Construct the new component IComponent* component = ct.alloc(m_ScriptInterface, obj); ENSURE(component); component->SetEntityHandle(ent); component->SetSimContext(m_SimContext); // Store a reference to the new component emap1.insert(std::make_pair(ent.GetId(), component)); emap2.insert(std::make_pair(ent.GetId(), component)); // TODO: We need to more careful about this - if an entity is constructed by a component // while we're iterating over all components, this will invalidate the iterators and everything // will break. // We probably need some kind of delayed addition, so they get pushed onto a queue and then // inserted into the world later on. (Be careful about immediation deletion in that case, too.) SEntityComponentCache* cache = ent.GetComponentCache(); ENSURE(cache != NULL && ct.iid < (int)cache->numInterfaces && cache->interfaces[ct.iid] == NULL); cache->interfaces[ct.iid] = component; return component;}
开发者ID:2asoft,项目名称:0ad,代码行数:59,
示例19: handle virtual void handle(boost::shared_ptr<Transceiver> &tr, boost::shared_ptr<Message> &message) { RecordType type = static_cast<RecordType>(message->type()); uint32_t fd = message->getFd(); uint16_t id = message->getId(); typename RequestsType::iterator cIt=_reqs.find(fd), cEnd=_reqs.end(); typename RequestsMap::iterator rIt,rEnd; bool isReqs=false; // cIt - connection (fd) iterator // rIt - request (req id) iterator if (cIt!=cEnd) { rIt=(*cIt).second.find(id); rEnd=(*cIt).second.end(); isReqs=true; }#ifdef FCGI_DEBUG std::cout<<"FCGI ["<<fd<<"] handle message type="<<type<<", id="<< id <<((isReqs && rIt!=rEnd) ? " FOUND" : " NOT FOUND")<<std::endl;#endif switch (type) { case BEGIN_REQUEST : if (isReqs && rIt==rEnd) { boost::shared_ptr<HandlerType> rq(new HandlerType(tr,message)); cIt->second.insert(make_pair(id, rq)); } else throw Exceptions::FcgiException("BEGIN_REQUEST on the same connection with id already exists.",0); break; case PARAMS: if (isReqs && rIt!=rEnd) { rIt->second->handleParams(message); } break; case IN: if (isReqs && rIt!=rEnd) { rIt->second->handleIN(message); } break; case DATA: if (isReqs && rIt!=rEnd) { rIt->second->handleData(message); } break; case ABORT_REQUEST: if (isReqs && rIt!=rEnd) { rIt->second->handleAbort(message); // cIt->second.erase(rIt); } break; case GET_VALUES: processGetValues(tr, message); break; default: break; } }
开发者ID:max1mbo,项目名称:fcgi,代码行数:59,
注:本文中的rq函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 C++ rq_data_dir函数代码示例 C++ rpmtdFreeData函数代码示例 |