MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / ToInterface

Method ToInterface

Source/Engine/Scripting/ScriptingObject.cpp:223–246  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

221}
222
223void* ScriptingObject::ToInterface(ScriptingObject* obj, const ScriptingTypeHandle& interfaceType)
224{
225 if (!obj || !interfaceType)
226 return nullptr;
227 const ScriptingType& objectType = obj->GetType();
228 const ScriptingType::InterfaceImplementation* interface = objectType.GetInterface(interfaceType);
229 void* result = nullptr;
230 if (interface && interface->IsNative)
231 {
232 // Native interface so just offset pointer to the interface vtable start
233 result = (byte*)obj + interface->VTableOffset;
234 }
235 else if (interface)
236 {
237 // Interface implemented in scripting (eg. C# class inherits C++ interface)
238 const ScriptingObjectsInterfaceKey key(obj, interfaceType);
239 if (!ScriptingObjectsInterfaceWrappers.TryGet(key, result))
240 {
241 result = interfaceType.GetType().Interface.GetInterfaceWrapper(obj);
242 ScriptingObjectsInterfaceWrappers.Add(key, result);
243 }
244 }
245 return result;
246}
247
248ScriptingObject* ScriptingObject::ToNative(MObject* obj)
249{

Callers

nothing calls this directly

Calls 4

GetInterfaceMethod · 0.80
GetTypeMethod · 0.45
TryGetMethod · 0.45
AddMethod · 0.45

Tested by

no test coverage detected