Run procedure from pointer?

Just starting out? Need help? Post your questions and find answers here.
Didaktik
User
User
Posts: 79
Joined: Fri Mar 14, 2014 2:12 pm

Run procedure from pointer?

Post 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)

Peyman
Enthusiast
Enthusiast
Posts: 203
Joined: Mon Dec 24, 2007 4:15 pm
Location: Iran

Re: Run procedure from pointer?

Post 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())
Sorry for my bad english.
User avatar
Keya
Addict
Addict
Posts: 1890
Joined: Thu Jun 04, 2015 7:10 am

Re: Run procedure from pointer?

Post 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)
User avatar
skywalk
Addict
Addict
Posts: 4223
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Run procedure from pointer?

Post by skywalk »

The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Run procedure from pointer?

Post by netmaestro »

Should be renamed by the team: CallFunctionFastButIPromiseToConvertToPrototypeAtMyEarliestOpportunity().

And - don't permit Autocomplete on it :twisted:
BERESHEIT
ToniPB
User
User
Posts: 13
Joined: Tue Dec 16, 2014 3:44 am

Re: Run procedure from pointer?

Post 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())
Post Reply