Page 1 of 1
Procedure address
Posted: Mon Jan 10, 2011 1:35 pm
by lambor734
Hi,
How can we get input from a function name, then address the function to find it?
For example :
Code: Select all
Procedure b()
-------
EndProcedure
Procedure a(func.s)
?????
?????
......
ProcedureReturn Address
EndProcedure
Debug a("b()") ;Address of b
Re: Procedure address
Posted: Mon Jan 10, 2011 1:45 pm
by DarkDragon
You can't dynamically, as purebasic is no scriptlanguage and the names of the functions aren't available after compiling anymore.
Re: Procedure address
Posted: Mon Jan 10, 2011 1:48 pm
by lambor734
Ie there is no way?
Re: Procedure address
Posted: Mon Jan 10, 2011 2:03 pm
by DarkDragon
lambor734 wrote:Ie there is no way?
Well, you could do it like this:
Code: Select all
Procedure b()
; -------
EndProcedure
Procedure a(func.s)
Protected *Address
If func = "b()"
*Address = @b()
EndIf
ProcedureReturn *Address
EndProcedure
Debug a("b()") ;Address of b
or like this:
Code: Select all
Procedure b()
; -------
EndProcedure
Global NewMap FunctionAddresses.i()
FunctionAddresses("b()") = @b()
; well, this function is useless then, as you can directly use FunctionAddresses(func)
Procedure a(func.s)
ProcedureReturn FunctionAddresses(func)
EndProcedure
Debug a("b()") ;Address of b
Re: Procedure address
Posted: Mon Jan 10, 2011 2:07 pm
by Booger
Is this what you are looking for? You can index these in an array to make a jump table to do all kinds of things.
Code: Select all
Procedure MyFunction()
Debug "MyFunction Called"
EndProcedure
Procedure DoSomething(address)
CallFunctionFast(address)
Debug address
EndProcedure
Function=@MyFunction()
DoSomething=@DoSomething()
CallFunctionFast(DoSomething,Function)
Re: Procedure address
Posted: Mon Jan 10, 2011 2:17 pm
by lambor734
Thank you, but I want every function of the user @ enter, he will find the address.
Ie is not already defined.
Like
Code: Select all
Function=@MyFunction() ; NoNoNo
DoSomething=@DoSomething() ;NoNoNo
Function = @InputBox ; yeah
Re: Procedure address
Posted: Mon Jan 10, 2011 2:24 pm
by DarkDragon
lambor734 wrote:Thank you, but I want every function of the user @ enter, he will find the address.
Ie is not already defined.
Like
Code: Select all
Function=@MyFunction() ; NoNoNo
DoSomething=@DoSomething() ;NoNoNo
Function = @InputBox ; yeah
Not possible in other ways that I explained, as the function names disappear after you compile your program. Its no script language.
Re: Procedure address
Posted: Mon Jan 10, 2011 2:25 pm
by Booger
Well, in that case I suggest Indexing your Function names into a string array, so you can do a string search. If you find the string that has been typed, jump to that address with your jump table of addresses you made.
So if:
StringTable(10)=Match
CallFunctionFast(JumpTable(10))
That's all I can offer base on the info you gave.
Re: Procedure address
Posted: Mon Jan 10, 2011 2:32 pm
by lambor734
Thank you, I ask in scripting languages such how is possible?
lua or Python or ...
If possible, leave a sample code.

Re: Procedure address
Posted: Mon Jan 10, 2011 2:42 pm
by Booger
PureBasic gets compiled into machine code. I suppose it could keep a string index of its compiled functions, but I don't think it does. I have looked at the compilers output a lot lately and not seen one anywhere.
Most, if not all, scripting languages are Virtual Machines or interpreters like the old 80's basics on the old machines. Hence they are slow and annoying IMO.
Re: Procedure address
Posted: Mon Jan 10, 2011 5:30 pm
by DarkDragon
Hello,
Booger wrote:Well, in that case I suggest Indexing your Function names into a string array, so you can do a string search. If you find the string that has been typed, jump to that address with your jump table of addresses you made.
So if:
StringTable(10)=Match
CallFunctionFast(JumpTable(10))
That's all I can offer base on the info you gave.
Booger, Booger, ... you ignore my posts, right?
Just look at my second example here:
http://www.purebasic.fr/english/viewtop ... 92#p343192
You don't need an array. A map is better for such a thing.
Re: Procedure address
Posted: Wed Dec 24, 2014 9:19 am
by SERware
lambor734 wrote:Hi,
How can we get input from a function name, then address the function to find it?
For example :
Code: Select all
Procedure b()
-------
EndProcedure
Procedure a(func.s)
?????
?????
......
ProcedureReturn Address
EndProcedure
Debug a("b()") ;Address of b
It is an old question, and I do not know if there was the "Runtime" key word because I'm new to PB:
Code: Select all
Runtime Procedure b()
Debug "b() called"
EndProcedure
bProcedureAddress=GetRuntimeInteger("b()")
CallFunctionFast(bProcedureAddress)
Debug bProcedureAddress ;Address of b