================ idProgram::FindFunction Searches for the specified function in the currently loaded script. A full namespace should be specified if not in the global namespace. Returns 0 if function not found. Returns >0 if function found. ================ */
| 1506 | ================ |
| 1507 | */ |
| 1508 | function_t *idProgram::FindFunction( const char *name ) const { |
| 1509 | int start; |
| 1510 | int pos; |
| 1511 | idVarDef *namespaceDef; |
| 1512 | idVarDef *def; |
| 1513 | |
| 1514 | assert( name ); |
| 1515 | |
| 1516 | idStr fullname = name; |
| 1517 | start = 0; |
| 1518 | namespaceDef = &def_namespace; |
| 1519 | do { |
| 1520 | pos = fullname.Find( "::", true, start ); |
| 1521 | if ( pos < 0 ) { |
| 1522 | break; |
| 1523 | } |
| 1524 | |
| 1525 | idStr namespaceName = fullname.Mid( start, pos - start ); |
| 1526 | def = GetDef( NULL, namespaceName, namespaceDef ); |
| 1527 | if ( !def ) { |
| 1528 | // couldn't find namespace |
| 1529 | return NULL; |
| 1530 | } |
| 1531 | namespaceDef = def; |
| 1532 | |
| 1533 | // skip past the :: |
| 1534 | start = pos + 2; |
| 1535 | } while( def->Type() == ev_namespace ); |
| 1536 | |
| 1537 | idStr funcName = fullname.Right( fullname.Length() - start ); |
| 1538 | def = GetDef( NULL, funcName, namespaceDef ); |
| 1539 | if ( !def ) { |
| 1540 | // couldn't find function |
| 1541 | return NULL; |
| 1542 | } |
| 1543 | |
| 1544 | if ( ( def->Type() == ev_function ) && ( def->value.functionPtr->eventdef == NULL ) ) { |
| 1545 | return def->value.functionPtr; |
| 1546 | } |
| 1547 | |
| 1548 | // is not a function, or is an eventdef |
| 1549 | return NULL; |
| 1550 | } |
| 1551 | |
| 1552 | /* |
| 1553 | ================ |
no test coverage detected