Object to function pointer?

BlitzMax Forums/BlitzMax Programming/Object to function pointer?

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Hi,

You can't convert between object<->function.

You'll have to create a wrapper object for the function, eg (untested):
Type TEntityCreator
   Method CreateEntity:TEntity()
     Return _cr()
   End Method

   Function Create:TEntityCreator( cr:TEntity() )
     Local t:TEntityCreator=New TEntityCreator
     t._cr=cr
     Return t
   End Function
   Field _cr:TEntity()
End Type

Function CreateEntityByClassname:TEntity(Class:String)
  Local c:TEntityCreator=TEntityCreator( MapValueForKey( TEntity.Classes,Class ) )
  If c Return c.CreateEntity()
  Throw "Unrecognized Classname:"+Class
End Function

Function RegisterClass(cr:TEntity(),name:String)
  MapInsert TEntity.Classes,name,TEntityCreator.Create( cr )
End Function