// interface int asCModule::BindImportedFunction(int index, int sourceId) { // First unbind the old function int r = UnbindImportedFunction(index); if( r < 0 ) return r; // Must verify that the interfaces are equal asCScriptFunction *dst = GetImportedFunction(index); if( dst == 0 ) return asNO_FUNCTION; asCScriptFunction *src = engine->GetScriptFunction(sourceId); if( src == 0 ) return asNO_FUNCTION; // Verify return type if( dst->returnType != src->returnType ) return asINVALID_INTERFACE; if( dst->parameterTypes.GetLength() != src->parameterTypes.GetLength() ) return asINVALID_INTERFACE; for( size_t n = 0; n < dst->parameterTypes.GetLength(); ++n ) { if( dst->parameterTypes[n] != src->parameterTypes[n] ) return asINVALID_INTERFACE; } bindInformations[index]->boundFunctionId = sourceId; engine->scriptFunctions[sourceId]->AddRef(); return asSUCCESS; }
// interface const char *asCModule::GetImportedFunctionDeclaration(int index) { asCScriptFunction *func = GetImportedFunction(index); if( func == 0 ) return 0; asASSERT(threadManager); asCString *tempString = &threadManager->GetLocalData()->string; *tempString = func->GetDeclarationStr(); return tempString->AddressOf(); }
int asCModule::BindImportedFunction(int index, int sourceID) { // Remove reference to old module int oldFuncID = bindInformations[index].importedFunction; if( oldFuncID != -1 ) { asCModule *oldModule = engine->GetModule(oldFuncID); if( oldModule != 0 ) { // Release reference to the module oldModule->ReleaseModuleRef(); } } if( sourceID == -1 ) { bindInformations[index].importedFunction = -1; return asSUCCESS; } // Must verify that the interfaces are equal asCModule *srcModule = engine->GetModule(sourceID); if( srcModule == 0 ) return asNO_MODULE; asCScriptFunction *dst = GetImportedFunction(index); if( dst == 0 ) return asNO_FUNCTION; asCScriptFunction *src = srcModule->GetScriptFunction(sourceID); if( src == 0 ) return asNO_FUNCTION; // Verify return type if( dst->returnType != src->returnType ) return asINVALID_INTERFACE; if( dst->parameterTypes.GetLength() != src->parameterTypes.GetLength() ) return asINVALID_INTERFACE; for( asUINT n = 0; n < dst->parameterTypes.GetLength(); ++n ) { if( dst->parameterTypes[n] != src->parameterTypes[n] ) return asINVALID_INTERFACE; } // Add reference to new module srcModule->AddModuleRef(); bindInformations[index].importedFunction = sourceID; return asSUCCESS; }
// interface int asCModule::BindImportedFunction(int index, int sourceId) { // First unbind the old function int r = UnbindImportedFunction(index); if( r < 0 ) return r; // Must verify that the interfaces are equal asCModule *srcModule = engine->GetModuleFromFuncId(sourceId); if( srcModule == 0 ) return asNO_MODULE; asCScriptFunction *dst = GetImportedFunction(index); if( dst == 0 ) return asNO_FUNCTION; asCScriptFunction *src = engine->GetScriptFunction(sourceId); if( src == 0 ) return asNO_FUNCTION; // Verify return type if( dst->returnType != src->returnType ) return asINVALID_INTERFACE; if( dst->parameterTypes.GetLength() != src->parameterTypes.GetLength() ) return asINVALID_INTERFACE; for( size_t n = 0; n < dst->parameterTypes.GetLength(); ++n ) { if( dst->parameterTypes[n] != src->parameterTypes[n] ) return asINVALID_INTERFACE; } // Add reference to new module srcModule->AddModuleRef(); bindInformations[index].importedFunction = sourceId; return asSUCCESS; }
// inteface int asCModule::BindAllImportedFunctions() { bool notAllFunctionsWereBound = false; // Bind imported functions int c = GetImportedFunctionCount(); for( int n = 0; n < c; ++n ) { asCScriptFunction *func = GetImportedFunction(n); if( func == 0 ) return asERROR; asCString str = func->GetDeclarationStr(); // Get module name from where the function should be imported const char *moduleName = GetImportedFunctionSourceModule(n); if( moduleName == 0 ) return asERROR; asCModule *srcMod = engine->GetModule(moduleName, false); int funcId = -1; if( srcMod ) funcId = srcMod->GetFunctionIdByDecl(str.AddressOf()); if( funcId < 0 ) notAllFunctionsWereBound = true; else { if( BindImportedFunction(n, funcId) < 0 ) notAllFunctionsWereBound = true; } } if( notAllFunctionsWereBound ) return asCANT_BIND_ALL_FUNCTIONS; return asSUCCESS; }