DoclerLabs / hexMachina

Releases, issues, documentation, website of hexMachina, framework written in Haxe
http://hexmachina.org
MIT License
44 stars 8 forks source link

Support passing function as param to flow, then executing it #264

Open gene-pavlovsky opened 6 years ago

gene-pavlovsky commented 6 years ago

I've added a function param to my flow file (it's intended as a callback). I then try to call it in flow. It throws an exception:

C:\foo\.haxelib\hexioc/0,34,0/src/hex/compiler/parser/flow/ObjectParser.hx:123: ERROR : Unknown expression
C:\foo\.haxelib\hexioc/0,34,0/src/hex/compiler/parser/flow/ObjectParser.hx:124: DEBUG : #pos(src/memberapplet/configuration/InitialContext.flow:5: characters 724-784)
C:\foo\.haxelib\hexioc/0,34,0/src/hex/compiler/parser/flow/ObjectParser.hx:125: func(memberAppletExternalInterfaceService.externalInterface)
C:\foo\.haxelib\hexioc/0,34,0/src/hex/compiler/parser/flow/ObjectParser.hx:126: DEBUG : ECall({ expr => EConst(CIdent(func)), pos => #pos(src/memberapplet/configuration/InitialContext.flow:5: characters 724-728) },[{ expr => EField({ expr => EConst(CIdent(memberAppletExternalInterfaceService)), pos => #pos(src/memberapplet/configuration/InitialContext.flow:5: characters 729-765) },externalInterface), pos => #pos(src/memberapplet/configuration/InitialContext.flow:5: characters 729-783) }])
src/memberapplet/configuration/InitialContext.flow:5: characters 724-784 : Invalid expression

As a workaround I pass that function to an initialization controller, which then calls it.

gene-pavlovsky commented 6 years ago

Another workaround is to pass an object that contains the function, and call it as object.function(). I suspect this might be already working in 0.35?

FrancisBourre commented 6 years ago

Thanks for the report. Can I see the original call (from the DSL) please?

gene-pavlovsky commented 6 years ago

It was like this

@context(
    params = {
        externalInterfaceProviderWrapper: memberapplet.ExternalInterfaceProviderWrapper
        externalInterfaceProvider: memberapplet.service.externalinterface.IExternalInterfaceProvider,
        setExternalInterface: com.transport.externalinterface.IExternalInterface->Void
    }
)
{

    @map_type("memberapplet.service.externalinterface.IMemberAppletExternalInterfaceService")
    memberAppletExternalInterfaceService = new js.memberapplet.service.externalinterface.MemberAppletExternalInterfaceService();

    memberAppletExternalInterfaceService.init(externalInterfaceProvider);
    setExternalInterface(memberAppletExternalInterfaceService.externalInterface);

The last line is the problem :) Current workaround: I pass this param externalInterfaceProviderWrapper: memberapplet.ExternalInterfaceProviderWrapper And then the last two lines are:

    memberAppletExternalInterfaceService.init(externalInterfaceProviderWrapper.externalInterfaceProvider);
    externalInterfaceProviderWrapper.setExternalInterface(memberAppletExternalInterfaceService.externalInterface);

This works.

gene-pavlovsky commented 6 years ago

I will try to see if we can update to 0.35 and maybe it's already working there. In any case if you don't already have a test case like this, makes sense to add one.