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

Method RegisterInterface

sdk/angelscript/source/as_scriptengine.cpp:1675–1734  ·  view source on GitHub ↗

interface

Source from the content-addressed store, hash-verified

1673
1674// interface
1675int asCScriptEngine::RegisterInterface(const char *name)
1676{
1677 if( name == 0 ) return ConfigError(asINVALID_NAME, "RegisterInterface", 0, 0);
1678
1679 // Verify if the name has been registered as a type already
1680 if( GetRegisteredType(name, defaultNamespace) )
1681 return asALREADY_REGISTERED;
1682
1683 // Use builder to parse the datatype
1684 asCDataType dt;
1685 asCBuilder bld(this, 0);
1686 bool oldMsgCallback = msgCallback; msgCallback = false;
1687 int r = bld.ParseDataType(name, &dt, defaultNamespace);
1688 msgCallback = oldMsgCallback;
1689 if( r >= 0 )
1690 {
1691 // If it is not in the defaultNamespace then the type was successfully parsed because
1692 // it is declared in a parent namespace which shouldn't be treated as an error
1693 if( dt.GetTypeInfo() && dt.GetTypeInfo()->nameSpace == defaultNamespace )
1694 return ConfigError(asERROR, "RegisterInterface", name, 0);
1695 }
1696
1697 // Make sure the name is not a reserved keyword
1698 size_t tokenLen;
1699 int token = tok.GetToken(name, strlen(name), &tokenLen);
1700 if( token != ttIdentifier || strlen(name) != tokenLen )
1701 return ConfigError(asINVALID_NAME, "RegisterInterface", name, 0);
1702
1703 r = bld.CheckNameConflict(name, 0, 0, defaultNamespace, true, false, false);
1704 if( r < 0 )
1705 return ConfigError(asNAME_TAKEN, "RegisterInterface", name, 0);
1706
1707 // Don't have to check against members of object
1708 // types as they are allowed to use the names
1709
1710 // Register the object type for the interface
1711 asCObjectType *st = asNEW(asCObjectType)(this);
1712 if( st == 0 )
1713 return ConfigError(asOUT_OF_MEMORY, "RegisterInterface", name, 0);
1714
1715 st->flags = asOBJ_REF | asOBJ_SCRIPT_OBJECT | asOBJ_SHARED;
1716 st->size = 0; // Cannot be instantiated
1717 st->name = name;
1718 st->nameSpace = defaultNamespace;
1719
1720 // Use the default script class behaviours
1721 st->beh.factory = 0;
1722 st->beh.addref = scriptTypeBehaviours.beh.addref;
1723 scriptFunctions[st->beh.addref]->AddRefInternal();
1724 st->beh.release = scriptTypeBehaviours.beh.release;
1725 scriptFunctions[st->beh.release]->AddRefInternal();
1726 st->beh.copy = 0;
1727
1728 allRegisteredTypes.Insert(asSNameSpaceNamePair(st->nameSpace, st->name), st);
1729 registeredObjTypes.PushLast(st);
1730
1731 currentGroup->types.PushLast(st);
1732

Callers

nothing calls this directly

Calls 8

GetTypeInfoMethod · 0.80
CheckNameConflictMethod · 0.80
PushLastMethod · 0.80
ParseDataTypeMethod · 0.45
GetTokenMethod · 0.45
AddRefInternalMethod · 0.45
InsertMethod · 0.45

Tested by

no test coverage detected