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

Thread: Module classes

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

    Module classes

    I'm currently working on a new way of developing modules and modules features that I'm so excited that I want to share a little initial info with all of you


    I will call this new way "module classes" Why the term classes? Some reasons:
    • because it will be possible to use dot notation for module methods
    • because in some way it will be the start of a new way of programming modules that will be very close to OOP but compiled
    • because if you have latest Power Basic compiler 905 you will be able to use PowerBasic Classes in thinBasic modules and use the same classes in thinBasic scripts wrapping the needed modules

    For the moment I will not give you too much inside details but I will show you what kind of scripts you will be able to use and how easy will be to develop new modules in this new way.

    So let's start from a thinBasic script example. Pay attention to the new syntax.
    Uses "LL2"
    '---The above module implements a CLASS named cLinkedList
    '---That CLASS name will be usable to define new object variables
    '---derived from that available classes
     
    Type tData
    x As Long
    y As Long
    w As Long
    h As Long
    AnArray(100) As Ext
    End Type
     
    '---Define a variable of cLinkedList CLASS
    '---During DIM of a new class variable nothing will happen
    '---other than internal allocation of a new variable derived from
    '---a class. You have to later call NEW to create a real object
    '---Out from the indicated class. See below
    Dim MyLL As cLinkedList
     
     
    Dim lCounter As Long
    Dim t1 As Double
    Dim t2 As Double
    Dim MyData As tData
     
    '---Create the object and call (if present) 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
     
    t1 = Timer
    For lCounter = 1 To 10000
    MyData.x = lCounter
    '---Call another method that will add some key/data pairs
    '---After method name, thinBasic Core engine will pass responsibility
    '---to parse syntax to module method so module programmer has all the freedom
    '---to define whatever syntax for the method
    '---In this case synatx is: .AddString(ByVal sKey As String, ByVal sData As String)
    Myll.AddString("CODE" & lCounter, MyData)
    Next
    t2 = Timer
     
    '---Call other methods
    MyLL.Count
     
    MsgBox 0, "Total time: " & Format$(t2 - t1, "#0.000")
     
    '---When appropriated (end of script or exit from function, ...), 
    '---default class destructor will be internally executed
    '---for every object variable
    '---Having a class destructor is not mandatory
    

    Now let's see what will be needed in module in order to tell thinBasic Core engine about new classes.
    Here below some PowerBasic code extrated from a module I'm working on as example and that I will distribute as source code for learning when done:

    '----------------------------------------------------------------------------
    Function LoadLocalSymbols Alias "LoadLocalSymbols" (Optional ByVal sPath As String) Export As Long
    ' 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 , CodePtr(LList_Create ))
    RetCode = thinBasic_Class_AddMethod(pClass, "_Destroy" , %thinBasic_ReturnNumber , CodePtr(LList_Free ))
     
    RetCode = thinBasic_Class_AddMethod(pClass, "AddString" , %thinBasic_ReturnNumber , CodePtr(LList_AddString ))
    RetCode = thinBasic_Class_AddMethod(pClass, "Count" , %thinBasic_ReturnNumber , CodePtr(LList_Count ))
     
    End If
    End Function
    
    Of course thinBasic module can have the usual way of managing module functions and new module classes all at the same time. So nothing will change in usual way of handling modules, you will just have a new weapon.

    Conclusion
    In next few weeks I will give more info and possibly a new thinBasic beta version where you will be able to experiment the creation of new classes.
    For the moment this is all I can tell you.
    Just to add that the above thinBasic script example is already working here in my machine.


    I will now work on the following areas:
    • integrating module classes into numeric and string expressions
    • passing objects to sub/functions as parameters
    • managing arrays of objects
    • integrate objects inside UDT

    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. #2

    Re: Module classes

    Interesting! Does this mean that we will be able to define classes in thinbasic too?

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

    Re: Module classes

    For the moment classes will work from a module point of view.
    When I will publish examples it will be more clear.

    What I can say now is that I'm building all the "inside" structures in order to consider the possibility to have classes also created directly in source code but if and when this will be reality I cannot say.
    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

  4. #4
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732

    Re: Module classes

    I see this as big step forward,

    can't wait to use it in modules


    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

  5. #5
    thinBasic MVPs kryton9's Avatar
    Join Date
    Nov 2006
    Location
    Naples, Florida & Duluth, Georgia
    Age
    67
    Posts
    3,869
    Rep Power
    404

    Re: Module classes

    Very exciting!
    Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
    Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server

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

    Re: Module classes

    Developed:
    • string and numeric expressions involving module classes methods
    • declaring and using classes inside functions/subs


    It seems to start to see the light
    I'm quite optimistic on this new set of features.
    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 author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10

    Re: Module classes

    I'm going on with this new idea.

    In order to test possibilities, I've added a Timer class in thinBasic Core engine and the syntax will be simple like:

    DIM MyTimer AS cTimer  '---Create a new object instantiated by cTimer class
    MyTimer = New cTimer   '---Call default constructor
    
    MyTimer.Start        '---Start timer
    MyTimer.Elapsed       '---If no Stop in the middle, it will give intermediate timing
    MyTimer.ElapsedToString("#0.000") '---Same as Elapsed but with possibility to format
    MyTimer.Stop        '---Stop the timer. From this time, Elapsed will return time between start and stop events
    
    Arrays of objects are already working

    I'm working now on:
    • REDIM arrays of objects on the fly calling default constructor/destructor
    • passing objects to functions as BYREF parameters
    • objects as UDT elements

    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

  8. #8

    Re: Module classes

    Cool, with thinAir support the user with auto completition?

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

    Re: Module classes

    That is a dream that sooner or later will become reality.
    At the moment is a bit later than sooner, sorry
    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
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732

    Re: Module classes

    It's looking great Eros!


    Thanks,
    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

Page 1 of 2 12 LastLast

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
  •