Page 1 of 1

[SOLVED] Possible to pass procedure pointer as parameter?

Posted: Wed Aug 07, 2019 10:51 am
by SkyManager
I have a question :

Is it possible to pass the pointer of a procedure as a parameter to another function/procedure so that it can be executed?

I have tried the following code,
it returns only the procedure pointer,
not running it!
How can I run a procedure after obtaining its pointer

Code: Select all

Procedure.s test()
  ProcedureReturn "test"
EndProcedure

Procedure run(ptr) ; Assume ptr is the procedure pointer
  Debug @ptr ; <----- This return only the pointer value, not executing the pointer
EndProcedure

run(@test())

Re: Possible to pass procedure pointer as parameter?

Posted: Wed Aug 07, 2019 10:57 am
by RSBasic

Code: Select all

Procedure.s test()
  ProcedureReturn "test"
EndProcedure

Procedure run(ptr) ; Assume ptr is the procedure pointer
  Debug PeekS(CallFunctionFast(ptr))
EndProcedure

run(@test())

Re: Possible to pass procedure pointer as parameter?

Posted: Wed Aug 07, 2019 11:10 am
by Little John
Help for CallFunctionFast() wrote:The use of prototypes is now strongly recommended.

Code: Select all

EnableExplicit

Prototype.s ProtoTest()

Procedure.s Test1()
   ProcedureReturn "Hello from test #1"
EndProcedure

Procedure.s Test2()
   ProcedureReturn "Hello from test #2"
EndProcedure


Procedure Run(MyTest.ProtoTest)
   Debug MyTest()
EndProcedure

Run(@Test1())
Run(@Test2())

Re: Possible to pass procedure pointer as parameter?

Posted: Thu Aug 08, 2019 6:14 am
by SkyManager
Thanks a lot :D