Call PB function by name
- Kwai chang caine
- Always Here
- Posts: 5357
- Joined: Sun Nov 05, 2006 11:42 pm
- Location: Lyon - France
Call PB function by name
Hello at all
Is it possible, to call a PB function like "MessageRequester()" or other by his name ?
Have a good day
Is it possible, to call a PB function like "MessageRequester()" or other by his name ?
Have a good day
The happiness is a road...
Not a destination
Not a destination
Re: Call PB function by name
I understand not exactely what you mean
Mean you this ?
Mean you this ?
Code: Select all
Procedure MessageRequester_()
ProcedureReturn MessageRequester("Error", "Activate firstly unicode in the PB compiler options !")
EndProcedure
Macro MessageRequester()
MessageRequester_()
EndMacro
Debug MessageRequester()
- Kwai chang caine
- Always Here
- Posts: 5357
- Joined: Sun Nov 05, 2006 11:42 pm
- Location: Lyon - France
Re: Call PB function by name
Hello WALBUS
I have see several code for call procedure with for exampler his adress
But first it's not PB function, but personal function
And the call his with the adress not the name
For my project i have searched a langage Script, and found RUBY, apparently a good one (Simple, portable, tiny)
But after i have change my mind, because i'm forced to include it into my project
Then after, i say to me it's perhaps more simple to try to do it myself, it's the reason why i search to create a PbScript program
I have see several code on the forum, but not really found what i search
For the moment i have do something a little bit like this, for numerous function of PB
So i wonder, if it's possible to send a text at the place of the name of the function, i'm not forced to writing each function
A little bit like this
I have see several code for call procedure with for exampler his adress
Code: Select all
Procedure Test_A()
Debug "A"
EndProcedure
Procedure Test_B(t.s)
Debug t
EndProcedure
Dim MyFnctions.i(100)
MyFnctions(0) = @Test_A()
MyFnctions(1) = @Test_B()
CallFunctionFast(MyFnctions(0))
CallFunctionFast(MyFnctions(1), @"B")
And the call his with the adress not the name
For my project i have searched a langage Script, and found RUBY, apparently a good one (Simple, portable, tiny)
But after i have change my mind, because i'm forced to include it into my project
Then after, i say to me it's perhaps more simple to try to do it myself, it's the reason why i search to create a PbScript program
I have see several code on the forum, but not really found what i search
For the moment i have do something a little bit like this, for numerous function of PB
Code: Select all
Procedure ScriptExec(LigneCommande.s)
Parametre$ = StringField(LigneCommande, 2, "(")
Parametre$ = RemoveString(Parametre$, Chr(32))
Param1$ = StringField(Parametre$, 1, ",")
Param2$ = StringField(StringField(Parametre$, 2, ","), 1, ")")
Select StringField(LigneCommande, 1, "(")
Case "MessageRequester"
MessageRequester(Param1$, Param2$)
EndSelect
EndProcedure
ScriptExec("MessageRequester(Hello, Kcc)")
A little bit like this
Code: Select all
RunFunction("NameOfPbFunction", *Param1, *Param2, *Param3, *Param4)
RunFunction("MessageRequester", @"Hello", @"Kcc")
Last edited by Kwai chang caine on Wed Jul 26, 2017 4:44 pm, edited 6 times in total.
The happiness is a road...
Not a destination
Not a destination
Re: Call PB function by name
Code: Select all
Procedure$ CallPBFunction(FunctionName$, Parameter1$="", Parameter2$="", Parameter3$="", Parameter4$="", Parameter5$="", Parameter6$="")
Protected Result$
Select FunctionName$
Case "MessageRequester" : Result$ = Str(MessageRequester(Parameter1$, Parameter2$, Val(Parameter3$)))
Case "InputRequester" : Result$ = InputRequester(Parameter1$, Parameter2$, Parameter3$, Val(Parameter4$))
Case "ElapsedMilliseconds" : Result$ = Str(ElapsedMilliseconds())
Case "Date" : Result$ = Str(Date(Val(Parameter1$), Val(Parameter2$), Val(Parameter3$), Val(Parameter4$), Val(Parameter5$), Val(Parameter6$)))
EndSelect
ProcedureReturn Result$
EndProcedure
Define Start = Val(CallPBFunction("ElapsedMilliseconds"))
Debug "Your name: " + CallPBFunction("InputRequester", "Test", "What is your name?")
Debug "Elapsed time: " + Str(Val(CallPBFunction("ElapsedMilliseconds")) - Start)
I guess there is a solution using ASM code.
Why OpenSource should have a license :: PB-CodeArchiv-Rebirth :: Pleasant-Dark (syntax color scheme) :: RegEx-Engine (compiles RegExes to NFA/DFA)
Manjaro Xfce x64 (Main system) :: Windows 10 Home (VirtualBox) :: Newest PureBasic version
- Kwai chang caine
- Always Here
- Posts: 5357
- Joined: Sun Nov 05, 2006 11:42 pm
- Location: Lyon - France
Re: Call PB function by name
Hello SICRO
You have posted in the same time of me
Yes your method his the same of mine, but i'm forced to rewriting all the functions manually
Furthermore, the management of parameters make problem, in some function if you send nothing or zero that's not works
Like this :
Thanks when even for your answer
You have posted in the same time of me
Yes your method his the same of mine, but i'm forced to rewriting all the functions manually
Furthermore, the management of parameters make problem, in some function if you send nothing or zero that's not works
Like this :
Code: Select all
Procedure$ CallPBFunction(FunctionName$, Parameter1$="", Parameter2$="", Parameter3$="", Parameter4$="", Parameter5$="", Parameter6$="")
Protected Result$
Select FunctionName$
Case "MessageRequester"
If Parameter3$ <> ""
Result$ = Str(MessageRequester(Parameter1$, Parameter2$, Val(Parameter3$)))
Else
Result$ = Str(MessageRequester(Parameter1$, Parameter2$))
EndIf
EndSelect
ProcedureReturn Result$
EndProcedure
CallPBFunction("MessageRequester", "Hello", "SICRO")
What the gods of programming hear you !!Sicro wrote:I guess there is a solution using ASM code.
The happiness is a road...
Not a destination
Not a destination
Re: Call PB function by name
hello Kwai chang caine, have you looked at the code posted here? http://www.purebasic.fr/english/viewtop ... 13&t=67832
Re: Call PB function by name
how about something like this:
Edit: added some fun flags to the request
norm.
Code: Select all
Import "User32.lib"
KCCMsgBox(Window.i, Body$, Title$, Flags.i=0) As "_MessageBoxW@16" ; "_MessageBoxA@16" A = non_unicode, W = unicode
EndImport
Dim MyFnctions.i(100)
MyFnctions(0) = @KCCMsgBox()
;some extra defines for fun!
#PB_MessageRequester_Button3=512
#PB_MessageRequester_Question=32
#PB_MessageRequester_AbortRetryIgnore=2
kccwin=0 ;
result=CallFunctionFast(MyFnctions(0), kccwin,@"Who new it was so difficult?",@"POTUS",#PB_MessageRequester_Question|#PB_MessageRequester_AbortRetryIgnore|#PB_MessageRequester_Button3)
Debug result
norm.
google Translate;Makes my jokes fall flat- Fait mes blagues tombent à plat- Machte meine Witze verpuffen- Eh cumpari ci vo sunari
Re: Call PB function by name
*
Last edited by Fig on Thu Jul 27, 2017 8:45 am, edited 1 time in total.
There are 2 methods to program bugless.
But only the third works fine.
Win10, Pb x64 5.71 LTS
But only the third works fine.
Win10, Pb x64 5.71 LTS
Re: Call PB function by name
I think we can learning a lot from this little thread
For coding efficient software :
Looking ever for the simplest and fastest way
Make codes never needless complicated
Think simple
For coding efficient software :
Looking ever for the simplest and fastest way
Make codes never needless complicated
Think simple
Re: Call PB function by name
Code: Select all
DisableDebugger
If #True=#False
label:
MessageRequester("","")
EnableASM
RET
label2:
MOV eax,0
PUSH eax
MOV eax,0
PUSH eax
label3:
DisableASM
EndIf
a.s="Title"
b.s="A text to display"
EnableASM
MOV eax,l_label
ADD eax,l_label3
SUB eax,l_label2
PUSH l_retour
PUSH b
PUSH a
!JMP eax
DisableASM
retour:
MessageRequester("next","forward instructions")
Last edited by Fig on Thu Jul 27, 2017 9:08 am, edited 2 times in total.
There are 2 methods to program bugless.
But only the third works fine.
Win10, Pb x64 5.71 LTS
But only the third works fine.
Win10, Pb x64 5.71 LTS
- Kwai chang caine
- Always Here
- Posts: 5357
- Joined: Sun Nov 05, 2006 11:42 pm
- Location: Lyon - France
Re: Call PB function by name
First, thanks at all for your answers
@Fig
What kind of magical alien code is it ???
I love it, i not understand...but i love when even
I don't know if it's possible to do that with all PB functions, mainly with the functions with string return like ReplaceString() ?
Thanks a lot for your little jewel
You have right, and i understand you
So be careful....sometime wife, like mine, can also be dangerous
@Normeus
It's a nice piece of code, thanks for it
That's works very well for MessageRequester() with call User32
But all the others functions of PB, i thinks it's not really possible to do that
For exampler, by random the function ReplaceString()
@JACK
It's an expression evaluator
It's sure i need this style of code for evaluate the expression send in the script
I have found a good one for that, with DANILO code
http://forums.purebasic.com/german/view ... =8&t=24256
But for the moment it's not exactely what i search
I search to simplify the call of PB functions
@WALBUS
Yes it's very interesting, but apparently not so simple...
I have also found this splendid code of Kapslok...but a little bit hard to understand for me
http://www.purebasic.fr/english/viewtop ... 08#p428387
Make PB fully scriptable can be again a new power feature for it, for remote machine by network or other....
Thanks for your interest and really nice GIF
@Fig
What kind of magical alien code is it ???
I love it, i not understand...but i love when even
I don't know if it's possible to do that with all PB functions, mainly with the functions with string return like ReplaceString() ?
Thanks a lot for your little jewel
You have right, and i understand you
So be careful....sometime wife, like mine, can also be dangerous
@Normeus
It's a nice piece of code, thanks for it
That's works very well for MessageRequester() with call User32
But all the others functions of PB, i thinks it's not really possible to do that
For exampler, by random the function ReplaceString()
@JACK
It's an expression evaluator
It's sure i need this style of code for evaluate the expression send in the script
I have found a good one for that, with DANILO code
http://forums.purebasic.com/german/view ... =8&t=24256
But for the moment it's not exactely what i search
I search to simplify the call of PB functions
@WALBUS
Yes it's very interesting, but apparently not so simple...
I have also found this splendid code of Kapslok...but a little bit hard to understand for me
http://www.purebasic.fr/english/viewtop ... 08#p428387
Make PB fully scriptable can be again a new power feature for it, for remote machine by network or other....
Thanks for your interest and really nice GIF
Last edited by Kwai chang caine on Thu Jul 27, 2017 9:11 am, edited 2 times in total.
The happiness is a road...
Not a destination
Not a destination
Re: Call PB function by name
It's not jewel, it's bullshit... But i am sure someone will fix it.
There are 2 methods to program bugless.
But only the third works fine.
Win10, Pb x64 5.71 LTS
But only the third works fine.
Win10, Pb x64 5.71 LTS
- Kwai chang caine
- Always Here
- Posts: 5357
- Joined: Sun Nov 05, 2006 11:42 pm
- Location: Lyon - France
Re: Call PB function by name
Make a day...where the gods give to me, the possibility of create "bulshit" like yours !!
Thanks a lot FIG , for spending your time for my REAL bushit
Thanks a lot FIG , for spending your time for my REAL bushit
The happiness is a road...
Not a destination
Not a destination