ErosOlmi
22-08-2010, 19:52
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
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