PDA

View Full Version : How to parse an array or a UDT parameter?



Michael Hartlef
30-10-2008, 11:22
Hi folks,

if I want to give a UDT or an array as a parameter, how would I parse that inside the SDK? And is there a way to determine the array elemets sizes inside the SDK?

Michael

ErosOlmi
30-10-2008, 11:53
Michael,

can you give me an example of the syntax you want to parse so I can be more precise?
In the meantime I will give you some additional info about how thinBasic internally handle variables.

thinBasic variables are maintained into a quite complex structure made of 3 levels:
1. script level
2. internal level
3. data level

Level 1 and 2 have its own information structure (UDT).
Level 3 is just memory data allocation.
Level 1 has pointer to level 2 and level 2 has a pointer to level 3.

Level 1: gives fast info to the parser (or to Modules) about a parsed variable
Level 2: gives more detailed info about the data handled by the variable
Level 3: just gives a pointer where the variable data is stored. In case of array, all elements are stored in a consecutive memory area.

Waiting for your syntax example.

Ciao
Eros

Michael Hartlef
30-10-2008, 12:11
Here you go:


result = myfunction( myarray() )

result = myfunction( myUDT )

ErosOlmi
30-10-2008, 12:28
Ok, lets reply for the case of a single or array variable. I will reply for UDT in another post

The following will parse the next token, will check if it is a variable and will return in pVar its LEVEL 1 pointer


DIM pVar AS LONG
thinBasic_VariableParsePtr(pVar)

If you want also let the user to optionally specify () after the array name just add the following:

IF thinBasic_CheckOpenParens_Optional THEN thinBasic_CheckCloseParens_Mandatory

'---Once you have the LEVEL 1 pointer you can get the LEVEL 2 pointer with


DIM pArray AS LONG
pArray = thinBasic_VariablePtrToDirectPtr(pVar)


'---Once you have the LEVEL 2 pointer you can get the LEVEL 3 pointer with


DIM pData AS LONG
pData = thinBasic_DirectPtrToDataPtr(pArray)


If you have pData pointer you can do what you like with it. For example you can use PowerBasic DIM ... AT to over impose a module variable or array AT pData position and change the content of the script variable. This method is very powerful.

I imagine you want to know how many elements are present in pArray. Use:

MyInfo = thinBasic_ArrayGetInfo(pArray, InfoType)
where InfoType can be:

'---Equates for InfoType
%Array_ElementsCount = 1& 'Total number of elements in the array
%Array_ElementSize = 2& 'The size of the single element (for example an array of LONGs will return 4)
%Array_Dimensions = 3& 'Number of dimensions (from 1 to 3)
%Array_Size = 4& 'Memory size allocated for the array. This will not compute the memory needed for strings
%Array_ElementsType = 10& 'Type of elements strored into the array. See equates for thinBasic_VariableGetInfo
%Array_ElementsAreFixed = 15& '%TRUE if elements are fixed size, like fixed strings or UDT

%Array_UBoundDim_1 = 91& 'Returns the Upper Bound of dimension 1
%Array_UBoundDim_2 = 92& 'Returns the Upper Bound of dimension 2
%Array_UBoundDim_3 = 93& 'Returns the Upper Bound of dimension 3

If all is ok and you did some test and they were successful, let me know and I will continue with some other info.

Ciao
Eros

ErosOlmi
30-10-2008, 12:39
Forgot to say to put an:

IF thinBasic_ErrorFree THEN
...
from time to time in order to avoid to go on in parsing if a runtime error has occurred.

Ciao
Eros

Michael Hartlef
30-10-2008, 22:34
Thanks for the info.

Michael Hartlef
14-06-2009, 18:49
Eros, is this info about getting the array data still correct? I get a GPF after trieing to get the pData pointer.

Edit: I uploaded a new TBGL_SpriteLoadsheet command and a sample so you can see how I do it.

ErosOlmi
14-06-2009, 19:28
I'm checking ...

ErosOlmi
14-06-2009, 20:00
Michael,

I've changed and committed in SVN server:
tbgl_Sprites2D.inc
TBGL_2D_Sprites_Sheet.tbasic

You need to change Exec_TBGL_SpriteLoadSheet function as you need. I just filled the array with dummy data.
You need to recompile thinBasic.TBGL.DLL

Mainly for what you need to do you do not need any data pointer. You just need to parse script variable ptr, redim the array, fill the array.

Let me know if all works correctly.

Ciao
Eros

Michael Hartlef
14-06-2009, 21:15
Works smoothly like butter and without the need of any workaround. :eusaclap:

ErosOlmi
14-06-2009, 21:41
What a ... celestial vision of ... programming :D

Michael Hartlef
14-06-2009, 21:47
Mmmh, what ever that means. I uploaded a new TBGL version. Thanks for the help!