PDA

View Full Version : Suggestion for enhancing thinBasic_LoadSymbol



Petr Schreiber
16-02-2010, 12:15
Hi guys,

I have one mad idea, which could solve 2 problems at the same time:

* problem #1, some errors at run time occur, because functions have wrong number of parameters, but currently thinBasic engine has no chance to detect it
* problem #2, where to take description for code tips?

The possible solution -> adding one more (optional) parameter to the thinBasic_LoadSymbol function, which would be string, specifying some kind of mask for the parameters function can use.

Simple example:


thinBasic_LoadSymbol "TBGL_Vertex", _
%thinBasic_ReturnNone, _
CODEPTR( Exec_TBGL_Vertex ), _
%thinBasic_ForceOverWrite, _
"(x,y,z)"


The last parameter as a whole can directly serve as help for code tips.

For checking, you can easily recognize the parameters should start with (, then 2 commas, then ).

In case of optional parameters, they would be indicated like in help file:


thinBasic_LoadSymbol "SomeFunction", _
%thinBasic_ReturnNone, _
CODEPTR( Exec_SomeFunction ), _
%thinBasic_ForceOverWrite, _
"(x,y[,z])"


This can again be used both by code tips and for syntax check at the time before parsing.

This is just idea for future, I don't need it currently, but wanted to let you know about it, and possibly discuss the problems of this solution.

Regarding the parameter description, instead of just "x" in above example, some special characters could be added to add more info for use with code tips:


thinBasic_LoadSymbol "SomeFunction", _
%thinBasic_ReturnNone, _
CODEPTR( Exec_SomeFunction ), _
%thinBasic_ForceOverWrite, _
"(x?X coordinate,y?Y coordinate[,z?Z coordinate])"


or to not bloat module, just command TB to seek for more info in help files automatically:



thinBasic_LoadSymbol "SomeFunction", _
%thinBasic_ReturnNone, _
CODEPTR( Exec_SomeFunction ), _
%thinBasic_ForceOverWrite, _
"(x,y[,z])@HELPFILE:thinbasic_tbgl.chm@"



Petr

ErosOlmi
16-02-2010, 18:41
Petr,

I'm checking you suggestion. I think we already discussed something similar in the past.

It is quite simple to implement it, at least for storing passed data (and I've already done it).
The problem is that we have to recompile all modules because an additional parameter, even if optional, must be known by all modules.
So, ... modules developed by me there is no problem.
Modules developed by you and others like Michael and Charles must be recompiled with the new thinCore.inc file I will distribute.

Regarding the syntax, I would prefer full syntax like "BYVAL X AS LONG [, BYVAL Y AS NUMBER]" or something like that because it would be better for help and for parsing instead to invent a new syntax.

If this is acceptable I can start working on it.
This would create a sort of self documented language.

Ciao
Eros

Petr Schreiber
16-02-2010, 19:11
Hi Eros,

for me it is 100% acceptable :)

Another alternative would be adding new:

thinBasic_DefSymbolParams(sName, sParams)

-> I am not sure how much it is suitable for non-PB SDK languages to have optional string parameter in thinBasic_LoadSymbol.
If OK, I would go the way you proposed.


Petr

ErosOlmi
17-02-2010, 11:11
Petr,

I will add a new SDK function:

Declare Function thinBasic_LoadSymbolEX _
Lib "thinCore.DLL" _
Alias "thinBasic_LoadSymbolEX" _
( _
ByVal SymbolName As String , _
ByVal ReturnCode As Long , _
ByVal FunctionOrSubPointer As Dword , _
Optional _
ByVal ForceOverWrite As Long , _
ByVal sSyntax As String , _
ByVal sHelp As String _
) As Long
In this way it will not be necessary to recompile any module.
Those willing to add syntax and/or help instructions to keywords will just need to change from
"thinBasic_LoadSymbol"
to
"thinBasic_LoadSymbolEX"
and add relevant informations.

I will post soon a new thinCore.dll and thinCore.inc files so you can test it. New core will have a new function called "APP_ListKeywordsAndSyntax[(KeySep [, SynSep])]" able to return keywords plus additional info.

Eros

Petr Schreiber
17-02-2010, 11:13
Perfect,

thanks a lot!

ErosOlmi
17-02-2010, 15:26
Petr,

in current beta 1.7.10.2 I've already developed what you suggested.
Check \thinBasic\SDK\SDK.ZIP and get PB version.
You will find new Core interface function "thinBasic_LoadSymbolEX" you can use to pass additional syntax and help to keywords of your modules.

To get back info from engine inside scripts you can use a new APP_... function called "APP_ListKeywordsAndSyntax" like in the following example:


Uses "console"
Uses "file"

DIM sKeys AS STRING
DIM aKeys() AS STRING
DIM nKeys AS LONG
DIM Count AS LONG
DIM sOut AS STRING
Dim sFileOut As String Value APP_ScriptPath & "KeywordsAndHelp.txt"

PrintL "Exporting keywords and syntax"
'---Get a string with keywords, syntax and help'
'---Each keyword is separated by $CRLF
'---Syntax and help is separated by $TAB
sKeys = APP_ListKeywordsAndSyntax
'---Is is possible to indicate keys and help separators like the following:
'sKeys = APP_ListKeywordsAndSyntax($CRLF, ";")

'---Parse string into an array
Parse sKeys, aKeys, $CRLF

'---Creates output buffer
nKeys = UBOUND(aKeys(1))
FOR Count = 1 TO nKeys
if aKeys(Count) = "" then iterate for
IF aKeys(Count) = "REM" then iterate for
IF aKeys(Count) = "|" then iterate for

sOut += aKeys(Count) & $CRLF
Console_ProgressBar(1, 35, 1, 45, 24, 1, nKeys, Count)

Next


PrintL "Saving file ", sFileOut

'---Save buffer into .txt file
FILE_Save(sFileOut, sOut)

PrintL "Done"
WaitKey


Let mw know.
Eros

Petr Schreiber
17-02-2010, 19:02
It works as expected, so I will prepare TBGL with this new SDK.


Thanks!,
Petr