interface
| 3076 | |
| 3077 | // interface |
| 3078 | int asCScriptEngine::RegisterGlobalFunction(const char *declaration, const asSFuncPtr &funcPointer, asDWORD callConv, void *auxiliary) |
| 3079 | { |
| 3080 | #ifdef AS_MAX_PORTABILITY |
| 3081 | if( callConv != asCALL_GENERIC ) |
| 3082 | return ConfigError(asNOT_SUPPORTED, "RegisterGlobalFunction", declaration, 0); |
| 3083 | #endif |
| 3084 | |
| 3085 | asSSystemFunctionInterface internal; |
| 3086 | int r = DetectCallingConvention(false, funcPointer, callConv, auxiliary, &internal); |
| 3087 | if( r < 0 ) |
| 3088 | return ConfigError(r, "RegisterGlobalFunction", declaration, 0); |
| 3089 | |
| 3090 | isPrepared = false; // TODO: Only set this after the validations have been completed, to avoid unnecessary Prepare in case no change was made |
| 3091 | |
| 3092 | // Put the system function in the list of system functions |
| 3093 | asSSystemFunctionInterface *newInterface = asNEW(asSSystemFunctionInterface)(internal); |
| 3094 | if( newInterface == 0 ) |
| 3095 | return ConfigError(asOUT_OF_MEMORY, "RegisterGlobalFunction", declaration, 0); |
| 3096 | |
| 3097 | asCScriptFunction *func = asNEW(asCScriptFunction)(this, 0, asFUNC_SYSTEM); |
| 3098 | if( func == 0 ) |
| 3099 | { |
| 3100 | asDELETE(newInterface, asSSystemFunctionInterface); |
| 3101 | return ConfigError(asOUT_OF_MEMORY, "RegisterGlobalFunction", declaration, 0); |
| 3102 | } |
| 3103 | |
| 3104 | func->sysFuncIntf = newInterface; |
| 3105 | |
| 3106 | asCBuilder bld(this, 0); |
| 3107 | r = bld.ParseFunctionDeclaration(0, declaration, func, true, &newInterface->paramAutoHandles, &newInterface->returnAutoHandle, defaultNamespace); |
| 3108 | if( r < 0 ) |
| 3109 | { |
| 3110 | // Set as dummy function before deleting |
| 3111 | func->funcType = asFUNC_DUMMY; |
| 3112 | asDELETE(func,asCScriptFunction); |
| 3113 | return ConfigError(asINVALID_DECLARATION, "RegisterGlobalFunction", declaration, 0); |
| 3114 | } |
| 3115 | |
| 3116 | if (func->templateSubTypes.GetLength()) |
| 3117 | { |
| 3118 | func->funcType = asFUNC_TEMPLATE; |
| 3119 | |
| 3120 | // Template functions are only supported for generic calling convention |
| 3121 | if (callConv != asCALL_GENERIC) |
| 3122 | return ConfigError(asNOT_SUPPORTED, "RegisterGlobalFunction", declaration, 0); |
| 3123 | } |
| 3124 | |
| 3125 | if (func->IsVariadic()) |
| 3126 | { |
| 3127 | // Variadic functions are only supported for generic calling convention |
| 3128 | if(callConv != asCALL_GENERIC) |
| 3129 | return ConfigError(asNOT_SUPPORTED, "RegisterGlobalFunction", declaration, 0); |
| 3130 | } |
| 3131 | |
| 3132 | // TODO: namespace: What if the declaration defined an explicit namespace? |
| 3133 | func->nameSpace = defaultNamespace; |
| 3134 | |
| 3135 | // Check name conflicts |