Results 1 to 10 of 10

Thread: suffix instead of a prefix

  1. #1
    Senior Member zak's Avatar
    Join Date
    Dec 2008
    Posts
    637
    Rep Power
    83

    suffix instead of a prefix

    Hi Petr
    in a future TBGL module, what about replacing the prefix TBGL_ by a suffix like _GL , something like: GetWindowKeyState_GL instead of TBGL_GetWindowKeyState
    i do not know how the other people feel, but for me the prefix are making chaos in my memory, it keeps poping up in my brain and hiding the original and most important word.

    i think remembering and manipulating:
    MouseGetPosX_GL
    MouseGetPosY_GL
    MouseGetLButton_GL
    CenterCursor_GL
    ..... etc
    in the brain dictionary of an average man/woman
    are easier than
    TBGL_MouseGetPosX
    TBGL_MouseGetPosY
    TBGL_MouseGetLButton
    TBGL_CenterCursor
    .... etc
    this is may be my own neuro health problem, but i feel i must express my idea, for a future contemplation.

  2. #2
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,157
    Rep Power
    736
    Hi Zak,

    I must say I still like the prefix way - and I think it will work in future better for stuff like code completion this way... (you first specify module, which quickly differentiates TBGL_IsWindow from UI module IsWindow) but that does not mean there is no solution to this problem

    As thinBASIC supports ALIAS keyword, you can redefine all the function names to suit your preference. Even better, such a keyword mod can be done in automated way using thinBasic itself

    Just run this script once, it will generate new, complete alias include file for you:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    Uses "File"
    uses "TBGL"
     
    Dim sListOfKeywords As String
    Dim Keyword()       As String
    Dim nKeywords       As Long
    Dim i               As Long
    Dim sFileContent    As String
     
    sListOfKeywords = APP_ListKeywords
     
    '---Parse string into an array
    nKeywords = Parse(sListOfKeywords, Keyword, $TAB)
     
    '---Creates output buffer
    sFileContent = "' This is include file of Zak's custom names for TBGL" + $CRLF(2)
    For i = 1 To nKeywords
      If StartsWith(Keyword(i), "TBGL_") Then
         sFileContent += "ALIAS " + Keyword(i) + " AS " + PetrsTBGLNameToZaksTBGLName(Keyword(i))+ $CRLF
      End If
    NEXT
     
    '---Save buffer into .INC file
    FILE_Save(APP_Path + "\Inc\" + "CustomTBGLFunctionNames.inc", sFileContent)
     
    Function PetrsTBGLNameToZaksTBGLName( sNameIn As String ) As String
      sNameIn  = Remove$(sNameIn, "TBGL_")
      sNameIn += "_GL"
      Return sNameIn  
    End Function
    ... and then, in your programs, just use:
    1
    #INCLUDE "CustomTBGLFunctionNames.inc"
    ... like in this example:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    Uses "TBGL"   
     
    #INCLUDE "CustomTBGLFunctionNames.inc"
     
    Function TBMain()
      Local hWnd      As DWord
      Local FrameRate As Double
       
      ' -- Create and show window
      hWnd = CreateWindowEx_GL("TBGL script - press ESC to quit", 640, 480, 32, %TBGL_WS_WINDOWED Or %TBGL_WS_CLOSEBOX)
      ShowWindow_GL
     
      ' -- Initialize lighting
      UseLighting_GL(%TRUE)
      UseLightSource_GL(%GL_LIGHT0, %TRUE)
     
      SetLightParameter_GL(%GL_LIGHT0, %TBGL_LIGHT_POSITION, 15, 10, 15, 1)
     
      ' -- Resets status of all keys
      ResetKeyState_GL()
     
      ' -- Main loop
      While IsWindow_GL(hWnd)
        FrameRate = GetFrameRate_GL
     
        ClearFrame_GL
          Camera_GL(15, 15, 15, 0, 0, 0)
           
          Color_GL(255, 128, 0)
          Box_GL(1, 1, 1)
     
        DrawFrame_GL
     
        ' -- ESCAPE key to exit application
        If GetWindowKeyState_GL(hWnd, %VK_ESCAPE) Then Exit While
     
      Wend
     
      DestroyWindow_GL
    End Function
    I know the TBGL_ prefix can be annoying, maybe in future when some dark magic like namespaces will be supported, you will be able to do something like:
    1
    2
    3
    4
    5
    6
    USING TBGL
      CreateWindowEx(...)
      ShowWindow
       
      ResetKeyState()
    END USING
    and so on. But that would need major change in the parser and also the IDE (to still provide context sensitive help), so I guess this is not comming that soon. But I hope the include file way is acceptable for you at the moment.


    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  3. #3
    Member
    Join Date
    Sep 2008
    Location
    Germany
    Posts
    406
    Rep Power
    57
    >>>> lol <<<<

  4. #4
    Member marcuslee's Avatar
    Join Date
    Sep 2008
    Location
    Kansas, USA
    Age
    43
    Posts
    222
    Rep Power
    39

    Wink Alias makes thinBasic stand out above the rest!

    I am not familiar with many other basic languages, but the Alias keyword seems to put thinBasic above the rest. Although there are limitations, you can use thinBasic in almost any way you want, making it easier for you.

    Go thinBasic!



    Mark

  5. #5
    Senior Member zak's Avatar
    Join Date
    Dec 2008
    Posts
    637
    Rep Power
    83
    this is a complete magic.
    like a magician who show a rabbit out of nothing, or like a topology in wich the impossible elastic shapes are possible, yes it works, i have read your message yesterday but because i have a mild influenza i was not able to try the example, so i have tried it today.
    your method can be used also by any one who may suffer from what i call :
    " Prefix Illness Syndrom ", and that more people will enjoy and attracted to the TBGL module.
    what can i say !!, you have saved me.
    thank you

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

    once again you have the ability to quicly find so cool and clever solutions.

    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

  7. #7
    thinBasic MVPs Michael Hartlef's Avatar
    Join Date
    Sep 2006
    Location
    Germany
    Age
    59
    Posts
    3,300
    Rep Power
    349
    Hi Petr,

    great job. Doesn't thinAir support userkeywords and so your script could create these too. Then you get the full support by syntax highlighted ALIASES.

    Cheers
    Michael

  8. #8
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,157
    Rep Power
    736
    Good idea,

    in case of custom defined keywords it can get complicated, as there can be some already present, so we cannot just overwrite the definition file. But what we can do is to get existing items, new items, combine them, make sure there are no duplicates and then save again. It sounds complicated, but thanks to ARRAY UNIQUE it is not
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    Uses "File", "Console"
    Uses "TBGL"
     
    Dim sListOfKeywords   As String
    Dim Keyword()         As String
    Dim nKeywords         As Long
    Dim nNewKeywords      As Long
       
    Dim sCustomKeywords         As String 
    Dim Lines()                 As String
    Dim nLines                  As Long 
    Dim CombinedLines()         As String 
     
    Dim i                 As Long 
    Dim newKeyword        As String
    Dim userKeywordsFile  As String
    Dim sFileContentINC   As String
    Dim sFileContentINI   As String
     
    PrintL "Generating include file..."
    sListOfKeywords = APP_ListKeywords
     
    '---Parse string into an array
    nKeywords = Parse(sListOfKeywords, Keyword, $TAB)
     
    '--- Create include file
    '---Creates output buffer
    sFileContentINC = "' This is include file of Zak's custom names for TBGL" + $CRLF(2)
    For i = 1 To nKeywords
      If StartsWith(Keyword(i), "TBGL_") Then  
         nNewKeywords    += 1
          
         newKeyword       = PetrsTBGLNameToZaksTBGLName(Keyword(i))
         sFileContentINC += "ALIAS " + Keyword(i) + " AS " + newKeyword + $CRLF
         sFileContentINI += newKeyword + $CRLF
      End If
    Next
     
    '---Save buffer into .INC file
    FILE_Save(APP_Path + "\Inc\" + "CustomTBGLFunctionNames.inc", sFileContentINC)
     
    PrintL "Generating custom keywords for thinAir..."
    PrintL
    '---Add new items to custom syntax file
    userKeywordsFile = APP_Path + "\thinAIR\Syntax\thinBasic\" + "thinBasic_Keywords_Usr.ini"
    If FILE_Size(userKeywordsFile) = 0 Then
      ' -- It is empty, we can safely overwrite it
      FILE_Save(userKeywordsFile, sFileContentINI)
    Else                                         
      ' -- We need to add only new items
      sCustomKeywords = FILE_Load(userKeywordsFile)
       
      ' -- We get existing items
      nLines          = Parse(sCustomKeywords, Lines, $CRLF)    
       
      ReDim Preserve Lines(nLines+nNewKeywords)
       
      ' -- Add new items to it
      For i = 1 To nNewKeywords
        newKeyword      = Parse$(sFileContentINI, $CRLF, i)
        Lines(nLines+i) = newKeyword
      Next
       
      ' -- Remove duplicates                             
      Array Unique Lines, CombinedLines 
       
      ' -- And save it back
      sFileContentINI = Join$(CombinedLines, $CRLF)                               
       
      FILE_Save(userKeywordsFile, sFileContentINI)
    End If
     
    PrintL
    PrintL "Done, press any key..."       
    WaitKey                                                                                                      
     
    Function PetrsTBGLNameToZaksTBGLName( sNameIn As String ) As String
      sNameIn  = Remove$(sNameIn, "TBGL_")
      sNameIn += "_GL"
      Return sNameIn  
    End Function
    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  9. #9
    Senior Member zak's Avatar
    Join Date
    Dec 2008
    Posts
    637
    Rep Power
    83
    the greatness itself,
    after applying Petr code above now the SetLightParameter_GL ... are highlighted , like in the picture:


  10. #10
    thinBasic MVPs Michael Hartlef's Avatar
    Join Date
    Sep 2006
    Location
    Germany
    Age
    59
    Posts
    3,300
    Rep Power
    349
    That is why I love thinBasic and all the people in this community. Problem, discussion and thanks because of our swiss army knife called thinBasic, solution found.

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
  •