Future<IClient::Result> ClientWS::callAsync(ConstStrA method, JSON::ConstValue params, JSON::ConstValue context) { Synchronized<FastLockR> _(lock); if (params == null) { params = jsonFactory->array(); } else if (!params->isArray()) { params = JSON::Container(jsonFactory->array()).add(params); } JSON::Builder bld(jsonFactory); natural thisid = idcounter++; JSON::Builder::CObject req = bld("id",thisid) .container() ("method",method) ("params",params); if (context != null) { req("context",context); } ConstStrA msg = jsonFactory->toString(*req); Future<Result> f; sendTextMessage(msg); waitingResults.insert(thisid,f.getPromise()); return f; }
void ClientWS::sendResponse(JSON::ConstValue id, JSON::ConstValue result, JSON::ConstValue error) { Synchronized<FastLockR> _(lock); JSON::Builder bld(jsonFactory); JSON::Builder::CObject req = bld("id",id) ("result",result) ("error",error); ConstStrA msg = jsonFactory->toString(*req); sendTextMessage(msg); }
int asCModule::GetGlobalVarIDByDecl(const char *decl) { if( isBuildWithoutErrors == false ) return asERROR; asCBuilder bld(engine, this); asCProperty gvar; bld.ParseVariableDeclaration(decl, &gvar); // TODO: Improve linear search // Search script functions for matching interface int id = -1; for( asUINT n = 0; n < scriptGlobals.GetLength(); ++n ) { if( gvar.name == scriptGlobals[n]->name && gvar.type == scriptGlobals[n]->type ) { id = n; break; } } if( id == -1 ) return asNO_GLOBAL_VAR; return moduleID | id; }
void TestChainTraverserComments::TestFixAnnotationChrFmt() { RTFFileContext context; CRtfDocumentChainBuilder bld(&context); CChainTraverser_FixCommentStyles trav(&bld); CRTF_String string(bld.GetContext(), Detached); trav.FixAnnotationChrFmt(&string); CRTF_Note note(bld.GetContext(), Detached); trav.FixAnnotationChrFmt(¬e); CRTF_ParaMarker para(bld.GetContext(), Detached); CRTF_CharacterProperties props(&context); RTFchrfmt cfmt(&context); cfmt.SetAnnotationChrfmt(asAnnotationConfirmed); cfmt.Flags.byBits.m_iHidden = 1; props.SetChrfmt(cfmt); para.SetCharFormat(&props); assertMessage(para.GetCharFormat()->GetChrfmt().GetAnnotationChrfmt()==asNone, _T("Annotation Chrfmt is always set to asNone now. We don't write them out any more.")); assertTest(para.GetCharFormat()->GetChrfmt().get_bHidden()); trav.FixAnnotationChrFmt(¶); assertTest(para.GetCharFormat()->GetChrfmt().GetAnnotationChrfmt()==asNone); assertTest(!para.GetCharFormat()->GetChrfmt().get_bHidden()); }
// interface int asCModule::GetTypeIdByDecl(const char *decl) { asCDataType dt; asCBuilder bld(engine, this); int r = bld.ParseDataType(decl, &dt); if( r < 0 ) return asINVALID_TYPE; return engine->GetTypeIdFromDataType(dt); }
int asCModule::GetMethodIDByDecl(const char *object, const char *decl) { if( isBuildWithoutErrors == false ) return asERROR; asCObjectType *ot = GetObjectType(object); if( ot == 0 ) return asINVALID_TYPE; asCBuilder bld(engine, this); asCScriptFunction func; int r = bld.ParseFunctionDeclaration(decl, &func); if( r < 0 ) return asINVALID_DECLARATION; // TODO: Improve linear search // Search script functions for matching interface int id = -1; for( asUINT n = 0; n < ot->methods.GetLength(); ++n ) { if( func.name == scriptFunctions[ot->methods[n]]->name && func.returnType == scriptFunctions[ot->methods[n]]->returnType && func.parameterTypes.GetLength() == scriptFunctions[ot->methods[n]]->parameterTypes.GetLength() ) { bool match = true; for( asUINT p = 0; p < func.parameterTypes.GetLength(); ++p ) { if( func.parameterTypes[p] != scriptFunctions[ot->methods[n]]->parameterTypes[p] ) { match = false; break; } } if( match ) { if( id == -1 ) id = ot->methods[n]; else return asMULTIPLE_FUNCTIONS; } } } if( id == -1 ) return asNO_FUNCTION; return moduleID | id; }
// interface int asCModule::GetFunctionIdByDecl(const char *decl) { if( isBuildWithoutErrors == false ) return asERROR; asCBuilder bld(engine, this); asCScriptFunction func(engine, this); int r = bld.ParseFunctionDeclaration(0, decl, &func, false); if( r < 0 ) return asINVALID_DECLARATION; // TODO: optimize: Improve linear search // Search script functions for matching interface int id = -1; for( size_t n = 0; n < globalFunctions.GetLength(); ++n ) { if( globalFunctions[n]->objectType == 0 && func.name == globalFunctions[n]->name && func.returnType == globalFunctions[n]->returnType && func.parameterTypes.GetLength() == globalFunctions[n]->parameterTypes.GetLength() ) { bool match = true; for( size_t p = 0; p < func.parameterTypes.GetLength(); ++p ) { if( func.parameterTypes[p] != globalFunctions[n]->parameterTypes[p] ) { match = false; break; } } if( match ) { if( id == -1 ) id = globalFunctions[n]->id; else return asMULTIPLE_FUNCTIONS; } } } if( id == -1 ) return asNO_FUNCTION; return id; }
int asCModule::GetImportedFunctionIndexByDecl(const char *decl) { if( isBuildWithoutErrors == false ) return asERROR; asCBuilder bld(engine, this); asCScriptFunction func; bld.ParseFunctionDeclaration(decl, &func); // TODO: Improve linear search // Search script functions for matching interface int id = -1; for( asUINT n = 0; n < importedFunctions.GetLength(); ++n ) { if( func.name == importedFunctions[n]->name && func.returnType == importedFunctions[n]->returnType && func.parameterTypes.GetLength() == importedFunctions[n]->parameterTypes.GetLength() ) { bool match = true; for( asUINT p = 0; p < func.parameterTypes.GetLength(); ++p ) { if( func.parameterTypes[p] != importedFunctions[n]->parameterTypes[p] ) { match = false; break; } } if( match ) { if( id == -1 ) id = n; else return asMULTIPLE_FUNCTIONS; } } } if( id == -1 ) return asNO_FUNCTION; return id; }
// interface int asCModule::GetGlobalVarIndexByDecl(const char *decl) { asCBuilder bld(engine, this); asCObjectProperty gvar; bld.ParseVariableDeclaration(decl, &gvar); // TODO: optimize: Improve linear search // Search script functions for matching interface int id = -1; for( size_t n = 0; n < scriptGlobals.GetLength(); ++n ) { if( gvar.name == scriptGlobals[n]->name && gvar.type == scriptGlobals[n]->type ) { id = (int)n; break; } } if( id == -1 ) return asNO_GLOBAL_VAR; return id; }