I'm sorry. I misunderstood your problem.
When registering the application interface, the engine still doesn't know of the Entity script class, so you can't register any functions that take or return that class. There are two ways of getting around this problem.
1. First register an interface from the application, e.g. RegisterInterface("IEntity"). The CreateEntity method can then be registered to return a handle to that interface, i.e. "RegisterObjectMethod("Area", "IEntity @CreateEntity(...)", ...). The Entity script class obviously needs implement the inteface for this to work. As the script that calls CreateEntity will receive an IEntity it needs to cast the handle to the Entity class before accessing its members, unless you registers methods directly with the interface.
2. Use the generic handle add-on, i.e.
CScriptHandle, to return a handle that the script can cast to Entity as needed. In this case the CreateEntity() method will be registered to return the generic handle, i.e. "ref @CreateEntity(...)", which the calling script can cast to an Entity class. The implementation of the CreateEntity() method needs to be modified to return a CScriptHandle object by value.
CScriptHandle Area::CreateEntity(...)
{
...
// Create the Entity instance
int typeId = module->GetTypeIdByDecl("Entity");
asIScriptObject *obj = reinterpret_cast<asIScriptObject*>(engine->CreateScriptObject(typeId));
// Prepare the generic handle object for returning the Entity instance
CScriptHandle handle;
handle.opAssign(obj, typeId);
// The generic handle will hold on to its own reference, so we need to release ours
obj->Release();
// Return the generic handle object by value (even though the method is registered as 'ref @')
return handle;
}
I had an idea for an improvement in the library because of this problem you've faced. The application could register the name of the shared class as part of the configuration. This would allow it to register objects taking or returning the type. When the script is then compiled it will fill in the members and properties of the type. This would greatly simplify the solution for your problem. I'm not sure I'll be able to implement this for version 2.24.0, but I'll add this to my to-do list for a later release.