Just starting out? Need help? Post your questions and find answers here.
lambor734
User
Posts: 40 Joined: Sun Dec 19, 2010 7:46 pm
Location: ovanaro
Post
by lambor734 » Mon Jan 10, 2011 1:35 pm
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
DarkDragon
Addict
Posts: 2344 Joined: Mon Jun 02, 2003 9:16 am
Location: Germany
Contact:
Post
by DarkDragon » Mon Jan 10, 2011 1:45 pm
You can't dynamically, as purebasic is no scriptlanguage and the names of the functions aren't available after compiling anymore.
bye,
Daniel
lambor734
User
Posts: 40 Joined: Sun Dec 19, 2010 7:46 pm
Location: ovanaro
Post
by lambor734 » Mon Jan 10, 2011 1:48 pm
Ie there is no way?
DarkDragon
Addict
Posts: 2344 Joined: Mon Jun 02, 2003 9:16 am
Location: Germany
Contact:
Post
by DarkDragon » Mon Jan 10, 2011 2:03 pm
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
Last edited by
DarkDragon on Mon Jan 10, 2011 2:11 pm, edited 1 time in total.
bye,
Daniel
Booger
Enthusiast
Posts: 134 Joined: Tue Sep 04, 2007 2:18 pm
Post
by Booger » Mon Jan 10, 2011 2:07 pm
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)
lambor734
User
Posts: 40 Joined: Sun Dec 19, 2010 7:46 pm
Location: ovanaro
Post
by lambor734 » Mon Jan 10, 2011 2:17 pm
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
DarkDragon
Addict
Posts: 2344 Joined: Mon Jun 02, 2003 9:16 am
Location: Germany
Contact:
Post
by DarkDragon » Mon Jan 10, 2011 2:24 pm
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.
bye,
Daniel
Booger
Enthusiast
Posts: 134 Joined: Tue Sep 04, 2007 2:18 pm
Post
by Booger » Mon Jan 10, 2011 2:25 pm
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.
lambor734
User
Posts: 40 Joined: Sun Dec 19, 2010 7:46 pm
Location: ovanaro
Post
by lambor734 » Mon Jan 10, 2011 2:32 pm
Thank you, I ask in scripting languages such how is possible?
lua or Python or ...
If possible, leave a sample code.
Booger
Enthusiast
Posts: 134 Joined: Tue Sep 04, 2007 2:18 pm
Post
by Booger » Mon Jan 10, 2011 2:42 pm
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.
DarkDragon
Addict
Posts: 2344 Joined: Mon Jun 02, 2003 9:16 am
Location: Germany
Contact:
Post
by DarkDragon » Mon Jan 10, 2011 5:30 pm
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.
bye,
Daniel
SERware
New User
Posts: 1 Joined: Wed Dec 24, 2014 9:06 am
Post
by SERware » Wed Dec 24, 2014 9:19 am
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