Page 1 of 1

Run procedure from pointer?

Posted: Mon Sep 26, 2016 4:26 pm
by Didaktik
how to start a procedure from another procedure pointer name on it?

example

Code: Select all


procedure Test(*callback)

    ...

    Run *callback

   ...
endprocedure

Test(@Procedure)


Re: Run procedure from pointer?

Posted: Mon Sep 26, 2016 4:48 pm
by Peyman
with CallFunctionFast and CallCFunctionFast

Code: Select all

Procedure Test(a, b)
  ProcedureReturn a * b
EndProcedure


Procedure Test2(*pointer)
  ProcedureReturn CallFunctionFast(*pointer, 23, 2) ; 46
EndProcedure


Debug Test2(@Test())

Re: Run procedure from pointer?

Posted: Mon Sep 26, 2016 4:51 pm
by Keya
you can also !call using inline asm, and PB's Prototype is another alternative i guess similar in nature to CallFunctionFast

Code: Select all

Prototype.i protoMyProc(var.i)

Procedure.i MyProcA(var.i)
  MessageRequester("Called", "MyProcA with parameter " + Str(var))
EndProcedure

Procedure.i MyProcB(var.i)
  MessageRequester("Called", "MyProcB with parameter " + Str(var))
EndProcedure


MyProc.protoMyProc = @MyProcA()
MyProc(3)

MyProc.protoMyProc = @MyProcB()
MyProc(5)

Re: Run procedure from pointer?

Posted: Mon Sep 26, 2016 4:56 pm
by skywalk

Re: Run procedure from pointer?

Posted: Mon Sep 26, 2016 5:14 pm
by netmaestro
Should be renamed by the team: CallFunctionFastButIPromiseToConvertToPrototypeAtMyEarliestOpportunity().

And - don't permit Autocomplete on it :twisted:

Re: Run procedure from pointer?

Posted: Mon Sep 26, 2016 7:25 pm
by Tenaja

Re: Run procedure from pointer?

Posted: Tue Sep 27, 2016 10:49 am
by ToniPB
This should work

Code: Select all

Prototype p_callback()

Procedure myCallback()
  Debug "Hello"
EndProcedure

Procedure Test(callback.p_callback)
  callback()
EndProcedure

Test(@myCallback())