Calling Procedures by Name

Just starting out? Need help? Post your questions and find answers here.
Foz
Addict
Addict
Posts: 1359
Joined: Tue Nov 13, 2007 12:42 pm
Location: Manchester, UK

Calling Procedures by Name

Post by Foz »

Is it possible, somehow, to call a procedure within the same executable, but by using the name of the procedure, or a label to locate the address of the procedure or some other way of doing it?

My current solutions is either a massive Select Case statement, or I use DLLs which have stringy return issues...
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: Calling Procedures by Name

Post by Danilo »

You could use maps or runtime procedures.

With maps, you need to initialize them with the function pointers first.
With runtime procedures, init is done automatically.

Code: Select all

Runtime Procedure abc()
    Debug "abc() called"
EndProcedure

Runtime Procedure xyz()
    Debug "xyz() called"
EndProcedure

Prototype NoArgs()
Define f.NoArgs

;---------------------------------
f = GetRuntimeInteger("xyz()")
If f : f() : EndIf

f = GetRuntimeInteger("abc()")
If f : f() : EndIf
;---------------------------------

NewMap functions.i()

functions("abc")=@abc()
functions("xyz")=@xyz()

f = functions("xyz")
If f : f() : EndIf

f = functions("abc")
If f : f() : EndIf
Foz
Addict
Addict
Posts: 1359
Joined: Tue Nov 13, 2007 12:42 pm
Location: Manchester, UK

Re: Calling Procedures by Name

Post by Foz »

Well damn, when did that runtime library get added?

It's been sat under my nose all this time...

Thanks Danilo!
Lothar Schirm
User
User
Posts: 54
Joined: Mon Nov 26, 2012 4:57 pm

Re: Calling Procedures by Name

Post by Lothar Schirm »

Hello Foz,

the runtime library has been added with Version 5.20 LTS. :lol:
Post Reply