Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: How to parse an array or a UDT parameter?

  1. #1

    How to parse an array or a UDT parameter?

    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

  2. #2
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10

    Re: How to parse an array or a UDT parameter?

    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
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  3. #3

    Re: How to parse an array or a UDT parameter?

    Here you go:

    result = myfunction( myarray() )
    
    result = myfunction( myUDT )
    

  4. #4
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10

    Re: How to parse an array or a UDT parameter?

    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:
    [code=freebasic]IF thinBasic_CheckOpenParens_Optional THEN thinBasic_CheckCloseParens_Mandatory[/code]

    '---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
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  5. #5
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10

    Re: How to parse an array or a UDT parameter?

    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
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  6. #6

    Re: How to parse an array or a UDT parameter?

    Thanks for the info.

  7. #7

    Re: How to parse an array or a UDT parameter?

    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.

  8. #8
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10

    Re: How to parse an array or a UDT parameter?

    I'm checking ...
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  9. #9
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10

    Re: How to parse an array or a UDT parameter?

    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
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  10. #10

    Re: How to parse an array or a UDT parameter?

    Works smoothly like butter and without the need of any workaround.

Page 1 of 2 12 LastLast

Similar Threads

  1. How to parse a parameter of a LONG type?
    By Michael Hartlef in forum Module SDK (Power Basic version)
    Replies: 7
    Last Post: 27-02-2007, 21:59

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •