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

Method RegisterMethodToObjectType

sdk/angelscript/source/as_scriptengine.cpp:2913–3075  ·  view source on GitHub ↗

internal

Source from the content-addressed store, hash-verified

2911
2912// internal
2913int asCScriptEngine::RegisterMethodToObjectType(asCObjectType *objectType, const char *declaration, const asSFuncPtr &funcPointer, asDWORD callConv, void *auxiliary, int compositeOffset, bool isCompositeIndirect)
2914{
2915#ifdef AS_MAX_PORTABILITY
2916 if( callConv != asCALL_GENERIC )
2917 return ConfigError(asNOT_SUPPORTED, "RegisterObjectMethod", objectType->name.AddressOf(), declaration);
2918#endif
2919
2920 asSSystemFunctionInterface internal;
2921 int r = DetectCallingConvention(true, funcPointer, callConv, auxiliary, &internal);
2922 if( r < 0 )
2923 return ConfigError(r, "RegisterObjectMethod", objectType->name.AddressOf(), declaration);
2924
2925 internal.compositeOffset = compositeOffset;
2926 internal.isCompositeIndirect = isCompositeIndirect;
2927 if( (compositeOffset || isCompositeIndirect) && callConv != asCALL_THISCALL )
2928 return ConfigError(asINVALID_ARG, "RegisterObjectMethod", objectType->name.AddressOf(), declaration);
2929
2930 // TODO: cleanup: This is identical to what is in RegisterMethodToObjectType
2931 // If the object type is a template, make sure there are no generated instances already
2932 if( objectType->flags & asOBJ_TEMPLATE )
2933 {
2934 for( asUINT n = 0; n < generatedTemplateTypes.GetLength(); n++ )
2935 {
2936 asCObjectType *tmpl = generatedTemplateTypes[n];
2937 if( tmpl->name == objectType->name &&
2938 tmpl->nameSpace == objectType->nameSpace &&
2939 !(tmpl->templateSubTypes[0].GetTypeInfo() && (tmpl->templateSubTypes[0].GetTypeInfo()->flags & asOBJ_TEMPLATE_SUBTYPE)) )
2940 {
2941 asCString msg;
2942 msg.Format(TXT_TEMPLATE_s_ALREADY_GENERATED_CANT_REGISTER, asCDataType::CreateType(tmpl, false).Format(tmpl->nameSpace).AddressOf());
2943 WriteMessage("",0,0, asMSGTYPE_ERROR, msg.AddressOf());
2944 return ConfigError(asERROR, "RegisterObjectMethod", objectType->name.AddressOf(), declaration);
2945 }
2946 }
2947 }
2948
2949 isPrepared = false; // TODO: Only set this after the validations have been completed, to avoid unnecessary Prepare in case no change was made
2950
2951 // Put the system function in the list of system functions
2952 asSSystemFunctionInterface *newInterface = asNEW(asSSystemFunctionInterface)(internal);
2953 if( newInterface == 0 )
2954 return ConfigError(asOUT_OF_MEMORY, "RegisterObjectMethod", objectType->name.AddressOf(), declaration);
2955
2956 asCScriptFunction *func = asNEW(asCScriptFunction)(this, 0, asFUNC_SYSTEM);
2957 if( func == 0 )
2958 {
2959 asDELETE(newInterface, asSSystemFunctionInterface);
2960 return ConfigError(asOUT_OF_MEMORY, "RegisterObjectMethod", objectType->name.AddressOf(), declaration);
2961 }
2962
2963 func->sysFuncIntf = newInterface;
2964 func->objectType = objectType;
2965 func->objectType->AddRefInternal();
2966
2967 asCBuilder bld(this, 0);
2968 r = bld.ParseFunctionDeclaration(func->objectType, declaration, func, true, &newInterface->paramAutoHandles, &newInterface->returnAutoHandle);
2969 if( r < 0 )
2970 {

Callers 1

RegisterScriptObjectFunction · 0.80

Calls 15

DetectCallingConventionFunction · 0.85
GetTypeInfoMethod · 0.80
IsVariadicMethod · 0.80
IsPropertyMethod · 0.80
PushLastMethod · 0.80
AddReferencesForFuncMethod · 0.80

Tested by

no test coverage detected