Page 2 of 2 FirstFirst 12
Results 11 to 20 of 20

Thread: Module classes

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

    Re: Module classes

    If you think some statement of Core can be transformed into compiled class to be used in next beta version, I can have a look while testing this new feature.

    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

  2. #12
    hello eros. one question to your first post to new module classes. the example with "ll2" (cLinkedList) module does working with

    Dim MyLL As cLinkedList '?
    
    or the development isn't perfect for that classes module? "method" and "class" are underlayed with blue syntax, so I can imagine this commands are still included in last thinbasic issue. I've tested this example and got an error (code 30) "Variable not defined or misspelled Keyword". that's correct?

    it's possible to know more about your compiling on powerbasic side? would be very nice to see more.

    bye, largo

  3. #13
    Hi Eros,

    I think we can get a near perfect match for modules written in Oxygen. I presume the value returned by the _create procedure is the address of the new object.

    It would be great to see the full source code of your test module showing how you do it in PB.

    Charles

    PS: one specific question: do you pass the object pointer automatically when calling the module class procedures or must this be retrieved with thinBasic_ParseLong
    Last edited by Charles Pegge; 01-12-2011 at 21:37.

  4. #14
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10
    I will publish as soon as I can a module example that implements a class but first I need to release new thinBasic version 1.9 (that is under development now)

    @Charles:
    yes it is a pointer to the new class.
    No, it is not necessary to parse the pointer but thinBasic will pass the pointer to all compiled method wrapper
    Please a little more patience and I will publish all.
    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. #15
    Thanks Eros,

    I wanted to find out whether any further bells and whistles were required from the Oxygen side to complete the OOP module interface.

    And as far as I can tell, no further constructs are required, and we are in sync

    Your scheme will also work quite well with non OOP modular code.

    Charles


    Here is a tentative outline for an Oxygen OOP based module.

    
    uses "oxygen"
    
    
    dim as string src
    
    
      src="
    
    
      #file "thinBasic_LList.dll"
    
    
    
    
    
    
      'SUBSET OF THINCORE
    
    
      %thinBasic_ReturnNone             =  0   'Used in thinBasic_LoadSymbol to define a sub
      %thinBasic_ReturnNumber           = 20   'Used in thinBasic_LoadSymbol to define a function returning a EXT number
      %thinBasic_ReturnString           = 30   'Used in thinBasic_LoadSymbol to define a function returning a string
      %thinBasic_ReturnCodeByte         =  1
      %thinBasic_ReturnCodeInteger      =  2
      %thinBasic_ReturnCodeWord         =  3
      %thinBasic_ReturnCodeDWord        =  4
      %thinBasic_ReturnCodeLong         =  5
      %thinBasic_ReturnCodeQuad         =  6
      %thinBasic_ReturnCodeSingle       =  7 
      %thinBasic_ReturnCodeDouble       =  8
      %thinBasic_ReturnCodeCurrency     =  9
      %thinBasic_ReturnCodeExt          = 10
      % thinBasic_ForceOverWrite        =  1    'Used in thinBasic_LoadSymbol to force symbol over writing
    
    
      library "thincore.dll"
    
    
      DECLARE FUNCTION  thinBasic_LoadSymbol                          _
                              (                                       _
                                BYVAL SymbolName AS STRING,           _
                                BYVAL ReturnCode AS LONG,             _
                                BYVAL FunctionOrSubPointer AS DWORD,  _
                                OPTIONAL BYVAL ForceOverWrite AS LONG _
                              ) AS LONG
    
    
    
    
      DECLARE SUB       thinBasic_ParseNumber                 (Result AS EXT)
      Declare SUB       thinBasic_ParseLong                   (Result As Long)
      Declare Function  thinBasic_ParseString                 (ByRef sResult As String) As Ext
      DECLARE FUNCTION  thinBasic_CheckOpenParens_Optional    () AS LONG
      DECLARE FUNCTION  thinBasic_CheckCloseParens_Mandatory  () AS LONG
      DECLARE FUNCTION  thinBasic_CheckComma_Optional         () AS LONG
    
    
    
    
    
    
      declare sub thinBasic_Class_Add (string cn,long m)
      declare sub  thinBasic_Class_AddMethod (long pt,string na,long rt, ad)
    
    
      library ""
    
    
      extern
    
    
      '==========
      Class LList
      '==========
    
    
      string s
      long   count
    
    
      method _create() as sys
      '======================
      '
      'CREATE PERSISTENT OBJECT
      '
      LList*p : @p=getmemory sizeof(p)
      '
      'INITIAL VALUES
      '
      p.s="ok"
      p.count=0
      return @p
      end method
    
    
    
    
      method _Free()
      '=============
      s=""
      freememory @this
      end method
    
    
    
    
      method addstring()
      '=========================
      count++
      end method
    
    
    
    
      method ListCount() as long
      '=========================
      return count
      end method
    
    
    
    
      end class
    
    
    
    
      '----------------------------------------------------------------------------
      Function LoadLocalSymbols Alias "LoadLocalSymbols" (Optional ByVal sPath As String) As Long, export
      ' This function is automatically called by thinCore whenever this DLL is loaded.
      ' This function MUST be present in every external DLL you want to use with thinBasic
      ' Use this function to initialize every variable you need and for loading the
      ' new symbol (read Keyword) you have created.
      '----------------------------------------------------------------------------
      
      local RetCode As Long
      local pClass  As Long
      
      pClass = thinBasic_Class_Add("cLinkedList", 0)
      
      '---If class was created
      If pClass Then
        RetCode = thinBasic_Class_AddMethod(pClass, "_Create" , %thinBasic_ReturnNumber , @LList._Create )
        RetCode = thinBasic_Class_AddMethod(pClass, "_Destroy" , %thinBasic_ReturnNumber ,@LList._Free )
      
        RetCode = thinBasic_Class_AddMethod(pClass, "AddString" , %thinBasic_ReturnNumber , @LList.AddString)
        RetCode = thinBasic_Class_AddMethod(pClass, "Count" , %thinBasic_ReturnNumber , @LList.Count)
      
      End If
    
    
      End Function
    
    
      end extern
    
    
    "
    
    
    o2_asmo src
    if len(o2_error) then
      msgbox 0,o2_error
      stop
    end if
    
    
    o2_exec
    

  6. #16
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10
    Yes, something like that.
    In PowerBasic than your class methods must be wrapped with standard functions to which thinCore engine will pass your class pointer.
    More or less like that:
      '--------------------------------------------------------------------------------------
      FUNCTION LList_AddString( _
                            BYVAL pList AS LONG    _
                          ) AS EXT
      '--------------------------------------------------------------------------------------
    
    
        LOCAL sKey  AS STRING
        LOCAL sData AS STRING
        LOCAL pp    AS LONG
    
    
    'MsgBox FuncName$ & Str$(pList)
        pp = thinBasic_CheckOpenParens_Optional
        thinBasic_ParseString sKey
        IF thinBasic_CheckComma_Mandatory THEN
    
    
          thinBasic_ParseString sData
    
    
          IF thinBasic_ErrorFree THEN
            IF pList THEN
              '---Use the magic REDIM ... AT and the trick is done
              REDIM iList(1& TO 1&) AS cIList AT pList
    
    
              FUNCTION = iList(1&).AddString(sKey, sData)
            END IF
          END IF
    
    
        END IF
        IF pp THEN thinBasic_CheckCloseParens_Mandatory
    
    
    
    
      END FUNCTION
    
    
      '--------------------------------------------------------------------------------------
      FUNCTION LList_Free( _
                            BYVAL pList AS LONG _
                          ) AS EXT
      '--------------------------------------------------------------------------------------
    '    If thinBasic_CheckOpenParens_Optional Then thinBasic_CheckCloseParens_Mandatory
    
    
        IF pList THEN
          '---Use the magic REDIM ... AT and the trick is done
          REDIM iList(1& TO 1&) AS cIList AT pList
    
    
          iList(1&).Free
    
    
        END IF
    
    
      END FUNCTION
    
    
      '--------------------------------------------------------------------------------------
      FUNCTION LList_Count( _
                            BYVAL pList AS LONG _
                          ) AS EXT
      '--------------------------------------------------------------------------------------
        IF thinBasic_CheckOpenParens_Optional THEN thinBasic_CheckCloseParens_Mandatory
    
    
        IF pList THEN
          '---Use the magic REDIM ... AT and the trick is done
          REDIM iList(1& TO 1&) AS cIList AT pList
    
    
          FUNCTION = iList(1&).Count
    
    
        END IF
    
    
      END FUNCTION
    
    You can use class pointer to point to your class and than call relevant methods

    Hope it is clear enough
    In any case please wait till thinBasic 1.9 will be out because it will fix some error in class handling

    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. #17
    Thanks Eros,

    How does your LList_Create work? Is it a constructor method that receives a null object pointer, or is it a conventional function which takes the role of class-factory like CoCreateInstance...

    My code above, assumes it is a constructor method with a null object pointer, but it could easily be placed outside the class and turned into a class factory function.

    (Sorry about the awful OOP jargon)

    Charles


    function LList_create() as sys
    '
    'CREATE PERSISTENT OBJECT
    '
    LList*p : @p=getmemory sizeof(p)
    '
    'INITIAL VALUES
    '
    p.s="ok"
    p.count=0
    return @p
    end function

    Last edited by Charles Pegge; 02-12-2011 at 04:32.

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

    All wrapper functions have a LONG parameter that is the pointer to the compiled class
    This LONG param (pList in this case) is the memory area allocated by thinCore to store a pointer to the instantiated class when you defined something like
      Dim MyLL      As cLinkedList
    
    Of course at DIM time, no class is created but just a variable whose type is Module CLASS. So that pointer will point to null
    Consider a module class variable like a DWORD with a structure associated with it. Every time it is encountered during script execution Core engine scan methods and if found it will call wrapped method passing a pointer to the DWORD

    When thinCore calls the constructor, it is responsibility tof the programmer to instantiate something, in this case a new module (internal) class named "cLList"
      '--------------------------------------------------------------------------------------
      FUNCTION LList_Create(  _
                            BYVAL pList AS LONG _
                            ) AS EXT
      '--------------------------------------------------------------------------------------
        LOCAL nUseString  AS EXT
        LOCAL nSortList   AS EXT
    
    
        IF thinBasic_CheckOpenParens_Optional THEN
          thinBasic_ParseNumber nUseString
          IF thinBasic_CheckComma_Optional THEN
            thinBasic_ParseNumber nSortList
          END IF
    
    
          thinBasic_CheckCloseParens_Mandatory
        END IF
    
    
        '---In any case I will create the list
        IF thinBasic_ErrorFree THEN
          IF pList THEN
            '---Use the magic REDIM ... AT and the trick is done
            REDIM iList(1& TO 1&) AS cIList AT pList
    
    
            iList(1&) = CLASS "cLList"
            iList(1&).Default(nUseString, nSortList)
    
    
          END IF
        END IF
    
    
      END FUNCTION
    
    Constructor is the wrapped function executed when thinCore encounters a class instantiation line like:
      '---Create the object and call default constructor
      '---Default constructor parsing is responsibility of module
      '---programmer so you can define whatever syntax for it
      '---In the below case syntax is:
      '   constructor[(ByVal UseStrings As Long [, ByVal SortItems As Long])]
      MyLL = New cLinkedList(%FALSE, %FALSE)
    
    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. #19
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10
    PS: sorry to all if I'm so "light" in replying but I'm currently in a working vortex in my company and I have very little time.
    Next week should be better.

    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. #20
    I look forward to the new possibilities Eros, thanks, and don't work too hard!
    Last edited by Charles Pegge; 02-12-2011 at 12:23.

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Classes and Methods
    By Charles Pegge in forum O2h Compiler
    Replies: 8
    Last Post: 05-12-2011, 15:56
  2. Article: Module classes
    By ErosOlmi in forum vBCms Comments
    Replies: 9
    Last Post: 30-06-2011, 16:38

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
  •