View Full Version : New possible idea: TBMain function automatically executed
ErosOlmi
29-07-2008, 11:23
Hi all,
I'm thinking about to have a default function to be executed automatically by thinBasic engine. Function could be named "TBMain".
How should it work?
script is loaded. All code outside any function or sub is executed as usual. Nothing will change comparing current behave.
just before finishing, Core engine will check if a function named "TBMain" exists.
if such function exists and has never been executed, it will automatically executed.
Many other languages have such an entry execution point. Conversion and understanding of applications could be more easy.
What do you think?
Regards
Eros
Petr Schreiber
29-07-2008, 12:27
Hi Eros,
thanks for this idea, if it will maintain compatibility with old scripts I see no problem.
If I get it right, in case of dirty code like this:
USES "Console"
PRINTL "A"
FUNCTION TBMAIN()
PRINTL "C"
WAITKEY
END FUNCTION
PRINTL "B"
... it will print A, B and C in the end?
I presume use of this function will be the same as in C or PB for example, it will simply behave as +/- entry point for application?
Will this function be able to return value? ( which can be checked in case some process shells out the script, or the script was invoked via COM interface ).
Petr
ErosOlmi
29-07-2008, 12:39
Yes Petr, exactly like you described.
Regarding return code I'm already adding the facility to return an error level code to the outside so script will be able to be used inside batch files or whatever will check return codes. I have to sync it with script execution both directly or in bundled form.
Ciao
Eros
Charles Pegge
29-07-2008, 12:50
Hi Eros,
I think a Main procedure is best left for the user to decide upon. We are accustome to having a WinMain or PBMain in PowerBasic but this hides the true entry point which one mightexpect in the main body of the program
For instance this is how FreeBasic starts off WinMain after doing any necessary initialisation:
end WinMain( GetModuleHandle( null ), null, Command( ), SW_NORMAL )
(Asmosphere uses the same method in the HelloWin and Opengl demos.)
Thus it makes no assumption about what windowing system / Main function will be used if any. The programmer has full control.
Petr Schreiber
29-07-2008, 13:04
Charles,
so you can specify any function like main using this?
I have never seen it before, but seems interesting and quite versatile.
Petr
Charles Pegge
29-07-2008, 13:27
Yes Petr, you can call it anything you please - winmain watermain thinmain etc . PB Inc. is quite sneeky the way they sell a PBWin and a PBCC separately. They could easily be the same product, but it makes commercial sense not to.
Being optional and not impacting on current code sounds like a very nice solution.
ErosOlmi
30-07-2008, 12:28
Yes, all is optional and more ;)
Example:
'---Show current default entry point function: usually TBMain
msgbox 0, "Current entry point function: " & app_getentrypoint
'---Set a new Entry Point function
app_SetEntryPoint ("MyNewMain")
msgbox 0, "Something to be executed"
For Counter as long = 1 to 100
'---Do something
next
'---This would be the default entry point
'---unless another is specified by app_SetEntryPoint
function TBMain() as long
msgbox 0, "Hi from " & Function_Name
end function
'---Any function having no params and returning a LONG
'---can be used as script entry point
function MyNewMain() as long
msgbox 0, "Hi from " & Function_Name
end function
I've setup in the following way:
"TBMain" function is by default the main thinBasic script entry point.
APP_GetEntryPoint new keyword will return the current Main function
APP_SetEntryPoint(StringExpression) new keyword can be used to set a new function entry point. Entry point function can be set to null string or to an existing function having no parameters and returning a LONG
just before exiting from the script, thinBasic engine will check if current entry point function exists. If it exists and HAS NEVER BEEN executed during the script running, it will be called.
I think this can give great flexibility on how to setup entry point behave.
If majority prefer, I can set default entry point to null string so there will not be a TBMain function. But I would prefer to leave it.
Let me know.
Ciao
Eros
Petr Schreiber
30-07-2008, 13:21
Well thought,
and nicely fits with the APP_* stuff design. So far best variant to me :)
In case script will not have defined any TBMain, what will app_getentrypoint return?
Petr
ErosOlmi
30-07-2008, 15:10
At the beginning of script execution, current entry point function name (TBMain at first) is checked.
If it does not exists, it will be set to empty string.
Ciao
Eros
Petr Schreiber
30-07-2008, 16:54
Hi Eros,
thanks for explanation, looks good to me.
Petr
Looks and sounds good Eros, a nice well thought out solution as far as I can tell! Thanks.
Michael Hartlef
31-07-2008, 21:27
I have no opinion about this as I never needed it.