interface
| 3269 | |
| 3270 | // interface |
| 3271 | asIScriptFunction *asCScriptEngine::GetGlobalFunctionByDecl(const char *decl) const |
| 3272 | { |
| 3273 | asCBuilder bld(const_cast<asCScriptEngine*>(this), 0); |
| 3274 | |
| 3275 | // Don't write parser errors to the message callback |
| 3276 | bld.silent = true; |
| 3277 | |
| 3278 | asCScriptFunction func(const_cast<asCScriptEngine*>(this), 0, asFUNC_DUMMY); |
| 3279 | int r = bld.ParseFunctionDeclaration(0, decl, &func, false, 0, 0, defaultNamespace); |
| 3280 | if( r < 0 ) |
| 3281 | return 0; |
| 3282 | |
| 3283 | asSNameSpace *ns = defaultNamespace; |
| 3284 | // Search script functions for matching interface |
| 3285 | while( ns ) |
| 3286 | { |
| 3287 | asIScriptFunction *f = 0; |
| 3288 | const asCArray<unsigned int> &idxs = registeredGlobalFuncs.GetIndexes(ns, func.name); |
| 3289 | for( unsigned int n = 0; n < idxs.GetLength(); n++ ) |
| 3290 | { |
| 3291 | const asCScriptFunction *funcPtr = registeredGlobalFuncs.Get(idxs[n]); |
| 3292 | if( funcPtr->objectType == 0 && |
| 3293 | func.returnType == funcPtr->returnType && |
| 3294 | func.parameterTypes.GetLength() == funcPtr->parameterTypes.GetLength() |
| 3295 | ) |
| 3296 | { |
| 3297 | bool match = true; |
| 3298 | for( asUINT p = 0; p < func.parameterTypes.GetLength(); ++p ) |
| 3299 | { |
| 3300 | if( func.parameterTypes[p] != funcPtr->parameterTypes[p] ) |
| 3301 | { |
| 3302 | match = false; |
| 3303 | break; |
| 3304 | } |
| 3305 | } |
| 3306 | |
| 3307 | if( match ) |
| 3308 | { |
| 3309 | if( f == 0 ) |
| 3310 | f = const_cast<asCScriptFunction*>(funcPtr); |
| 3311 | else |
| 3312 | // Multiple functions |
| 3313 | return 0; |
| 3314 | } |
| 3315 | } |
| 3316 | } |
| 3317 | |
| 3318 | if( f ) |
| 3319 | return f; |
| 3320 | |
| 3321 | // Recursively search parent namespaces |
| 3322 | ns = GetParentNameSpace(ns); |
| 3323 | } |
| 3324 | |
| 3325 | return 0; |
| 3326 | } |
| 3327 | |
| 3328 |