MCPcopy Create free account
hub / github.com/anjo76/angelscript / RegisterGlobalFunction

Method RegisterGlobalFunction

sdk/angelscript/source/as_scriptengine.cpp:3078–3185  ·  view source on GitHub ↗

interface

Source from the content-addressed store, hash-verified

3076
3077// interface
3078int 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

Callers 15

ConfigureEngineFunction · 0.80
ConfigureEngineFunction · 0.80
ConfigureEngineFunction · 0.80
ConfigureEngineFunction · 0.80
ConfigureEngineFunction · 0.80
ConfigureEngineFunction · 0.80
ConfigureEngineFunction · 0.80
RegisterScriptFunctionFunction · 0.80
ConfigEngineFromStreamFunction · 0.80
RegisterThreadSupportMethod · 0.80

Calls 13

DetectCallingConventionFunction · 0.85
IsVariadicMethod · 0.80
CheckNameConflictMethod · 0.80
IsPropertyMethod · 0.80
PushLastMethod · 0.80
PutMethod · 0.80
AddReferencesForFuncMethod · 0.80
GetLengthMethod · 0.45
AddressOfMethod · 0.45

Tested by 15

TestFunction · 0.64
TestExecute1ArgFunction · 0.64
TestMultipleInheritance3Function · 0.64
TestFunction · 0.64
TestFunction · 0.64
Test2Function · 0.64
Test3Function · 0.64
Test4Function · 0.64
Test8Function · 0.64
TestRetRefFunction · 0.64
TestFunction · 0.64
Test2Function · 0.64