internal
| 1234 | #ifndef AS_NO_COMPILER |
| 1235 | // internal |
| 1236 | int asCModule::AddScriptFunction(int sectionIdx, int declaredAt, int id, const asCString &funcName, const asCDataType &returnType, const asCArray<asCDataType> ¶ms, const asCArray<asCString> ¶mNames, const asCArray<asETypeModifiers> &inOutFlags, const asCArray<asCString *> &defaultArgs, bool isInterface, asCObjectType *objType, bool isGlobalFunction, asSFunctionTraits funcTraits, asSNameSpace *ns) |
| 1237 | { |
| 1238 | asASSERT(id >= 0); |
| 1239 | |
| 1240 | // Store the function information |
| 1241 | asCScriptFunction *func = asNEW(asCScriptFunction)(m_engine, this, isInterface ? asFUNC_INTERFACE : asFUNC_SCRIPT); |
| 1242 | if( func == 0 ) |
| 1243 | { |
| 1244 | // Free the default args |
| 1245 | for( asUINT n = 0; n < defaultArgs.GetLength(); n++ ) |
| 1246 | if( defaultArgs[n] ) |
| 1247 | asDELETE(defaultArgs[n], asCString); |
| 1248 | |
| 1249 | return asOUT_OF_MEMORY; |
| 1250 | } |
| 1251 | |
| 1252 | if( ns == 0 ) |
| 1253 | ns = m_engine->nameSpaces[0]; |
| 1254 | |
| 1255 | // All methods of shared objects are also shared |
| 1256 | if( objType && objType->IsShared() ) |
| 1257 | funcTraits.SetTrait(asTRAIT_SHARED, true); |
| 1258 | |
| 1259 | func->name = funcName; |
| 1260 | func->nameSpace = ns; |
| 1261 | func->id = id; |
| 1262 | func->returnType = returnType; |
| 1263 | if( func->funcType == asFUNC_SCRIPT ) |
| 1264 | { |
| 1265 | func->scriptData->scriptSectionIdx = sectionIdx; |
| 1266 | func->scriptData->declaredAt = declaredAt; |
| 1267 | } |
| 1268 | func->parameterTypes = params; |
| 1269 | func->parameterNames = paramNames; |
| 1270 | func->inOutFlags = inOutFlags; |
| 1271 | func->defaultArgs = defaultArgs; |
| 1272 | func->objectType = objType; |
| 1273 | if( objType ) |
| 1274 | objType->AddRefInternal(); |
| 1275 | func->traits = funcTraits; |
| 1276 | |
| 1277 | asASSERT( params.GetLength() == inOutFlags.GetLength() && params.GetLength() == defaultArgs.GetLength() ); |
| 1278 | |
| 1279 | // Verify that we are not assigning either the final or override specifier(s) if we are registering a non-member function |
| 1280 | asASSERT( !(!objType && funcTraits.GetTrait(asTRAIT_FINAL)) ); |
| 1281 | asASSERT( !(!objType && funcTraits.GetTrait(asTRAIT_OVERRIDE)) ); |
| 1282 | |
| 1283 | // The internal ref count was already set by the constructor |
| 1284 | m_scriptFunctions.PushLast(func); |
| 1285 | m_engine->AddScriptFunction(func); |
| 1286 | |
| 1287 | // Compute the signature id |
| 1288 | if( objType ) |
| 1289 | func->ComputeSignatureId(); |
| 1290 | |
| 1291 | // Add reference |
| 1292 | if( isGlobalFunction ) |
| 1293 | m_globalFunctions.Put(func); |
no test coverage detected