How to call a procedure via its address?

Just starting out? Need help? Post your questions and find answers here.
ale870
Enthusiast
Enthusiast
Posts: 180
Joined: Wed Jul 09, 2008 7:02 am
Contact:

How to call a procedure via its address?

Post by ale870 »

Hello,

I need to store some procedure addreses in an array, then I need to call it using its address. Example:

Code: Select all

dim address(10)
address(0) = @myProc1()
address(1) = @myProc2()
address(2) = @myProc3()
address(3) = @myProc4()

call proc(address(1)) ; <== just for example!!!
Last line is dummy, since I don't know the real syntax.

How can I do it?

Thank you for your help!
Heathen
Enthusiast
Enthusiast
Posts: 498
Joined: Tue Sep 27, 2005 6:54 pm
Location: At my pc coding..

Post by Heathen »

CallFunctionFast()
I love Purebasic.
User avatar
Comtois
Addict
Addict
Posts: 1432
Joined: Tue Aug 19, 2003 11:36 am
Location: Doubs - France

Post by Comtois »

prototype

Code: Select all

Prototype toto(a,b,c=4)

Define Truc.toto

Declare Bidule(a,b,c)
Truc=@Bidule()

Debug Truc(3,5)
Debug Truc(3,5,6)

Procedure Bidule(a,b,c)
  ProcedureReturn a+b+c
EndProcedure
Using CallFunctionFast

Code: Select all

Declare MyProc1(a,b)
Declare MyProc2(a,b)

Dim Address(1)
Address(0)=@MyProc1()
Address(1)=@MyProc2()   

Procedure MyProc1(a,b)
  ProcedureReturn a+b
EndProcedure

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

For i=0 To 1
  Debug CallFunctionFast(Address(i),2,5)
Next i 
using prototype

Code: Select all

Declare MyProc1(a,b)
Declare MyProc2(a,b)

Prototype Toto(a,b)

Define Truc.toto
Dim Address(1)
Address(0)=@MyProc1()
Address(1)=@MyProc2()   
Procedure MyProc1(a,b)
  ProcedureReturn a+b
EndProcedure

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

For i=0 To 1
  Truc=Address(i)
  Debug Truc(2,5)
Next i 
Please correct my english
http://purebasic.developpez.com/
ale870
Enthusiast
Enthusiast
Posts: 180
Joined: Wed Jul 09, 2008 7:02 am
Contact:

Post by ale870 »

Simply wonderful!
This is really what I was looking for!

Thank you to everyone!!! :D
User avatar
pdwyer
Addict
Addict
Posts: 2813
Joined: Tue May 08, 2007 1:27 pm
Location: Chiba, Japan

Post by pdwyer »

@Comtois Nice! clear and concise! :D
Paul Dwyer

“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
Post Reply