
a\\func(...) as shortcut for a\func(a,...)
a\\func(...) as shortcut for a\func(a,...)
See topic, nothing to add 

Re: a\\func(...) as shortcut for a\func(a,...)
This method is already implemented as Interfaces:
Code: Select all
Interface Test
func.i(b.i, c.i)
EndInterface
Structure TestS
*Functions
Value.i
EndStructure
Procedure func(*a.TestS, b.i, c.i)
ProcedureReturn *a\Value*b+c
EndProcedure
Procedure New(Value.i)
Protected *Element.TestS = AllocateStructure(TestS)
*Element\Functions = ?Functions
*Element\Value= Value
ProcedureReturn *Element
DataSection
Functions:
Data.i @func()
EndDataSection
EndProcedure
Define a.Test = New(1)
Define a2.Test = New(2)
Define b.i = 4
Define c.i = 6
Debug a\func(b, c)
Debug a2\func(1, 0)
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and more ― Typeface - Sprite-based font include/module
Lizard - Script language for symbolic calculations and more ― Typeface - Sprite-based font include/module
Re: a\\func(...) as shortcut for a\func(a,...)
I know, but i think, something like this is more ellgant, easier to understand:
it would be nice to write here simple:
And by the way - when the structre could handle automatic prototype like this:
it would be very nice. Maybe it would be nice to have default-values for structures.... Then it would be perfect, like
In this case, you don't need a "new" anymore.
Code: Select all
Prototype _GetCounter(*self)
Prototype _SetCounter(*self,value)
Prototype _AddCounter(*self,value=1)
Structure Counter
Get._GetCounter
Set._SetCounter
Add._AddCounter
_value.i
EndStructure
Procedure counter_Get(*self.counter)
ProcedureReturn *self\_value
EndProcedure
Procedure counter_Set(*self.counter,value)
*self\_value=value
ProcedureReturn *self\_value
EndProcedure
Procedure counter_Add(*self.counter,value=1)
*self\_value+value
ProcedureReturn *self\_value
EndProcedure
Procedure New_counter(value=0)
Protected *self.counter=AllocateStructure(counter)
*self\Get=@counter_Get()
*self\Set=@counter_Set()
*self\Add=@counter_Add()
*self\_value=value
ProcedureReturn *self
EndProcedure
Macro DisposeObject(a)
FreeStructure(a)
EndMacro
*x.counter=New_counter()
Debug *x\Get(*x)
*x\Set(*x,10)
Debug *x\get(*x)
Debug *x\Add(*x)
DisposeObject(*x)
Code: Select all
Debug *x\\Get()
*x\\Set(10)
Debug *x\\get()
Debug *x\\Add()
Code: Select all
Structure Counter
Get.i (*self.counter)
Set.i (*self.counter,value)
Add.i (*self.counter,value=1)
_value.i
EndStructure
Code: Select all
Structure Counter
Get.i (*self.counter) = @counter_get()
Set.i (*self.counter,value) = @counter_set()
Add.i (*self.counter,value=1) = @counter_add()
_value.i = 1
EndStructure
Code: Select all
x.counter
debug x\\Get()
x\\Set(10)
Debug x\\get()
Debug x\\Add()
Re: a\\func(...) as shortcut for a\func(a,...)
For your first part:
For your second part:
Yes it whould be nice to initialize a Interface by a simple definition, without a "new" but often the "new" function do more than a simple setting of values.
Edit:
I use prototypes in structures also very often, and I like it, but I think Interfaces are the native way in PB to use methodes for objects and the use of prototypes in structures is a bonus.
Code: Select all
Interface Counter
Get()
Set(value)
Add(value=1)
EndInterface
Structure CounterS
*Functions
Value.i
EndStructure
Procedure counter_Get(*self.CounterS)
ProcedureReturn *self\Value
EndProcedure
Procedure counter_Set(*self.CounterS,value)
*self\Value=value
ProcedureReturn *self\Value
EndProcedure
Procedure counter_Add(*self.CounterS,value=1)
*self\Value+value
ProcedureReturn *self\Value
EndProcedure
Procedure New_counter(value=0)
Protected *self.CounterS=AllocateStructure(CounterS)
*self\Functions = ?Functions
DataSection
Functions:
Data.i @counter_Get(), @counter_Set(), @counter_Add()
EndDataSection
ProcedureReturn *self
EndProcedure
Macro DisposeObject(a)
FreeStructure(a)
EndMacro
*x.counter=New_counter()
Debug *x\Get()
*x\Set(10)
Debug *x\Get()
Debug *x\Add()
DisposeObject(*x)
Yes it whould be nice to initialize a Interface by a simple definition, without a "new" but often the "new" function do more than a simple setting of values.
Edit:
I use prototypes in structures also very often, and I like it, but I think Interfaces are the native way in PB to use methodes for objects and the use of prototypes in structures is a bonus.
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and more ― Typeface - Sprite-based font include/module
Lizard - Script language for symbolic calculations and more ― Typeface - Sprite-based font include/module
Re: a\\func(...) as shortcut for a\func(a,...)
I personal think, that Objects with Interaface (and structures) are not an easy to handle option. You must create first a Interface, then a structure, "connect" them, fill the vtable and so on. When you extend the object, you must be carefull, that you insert the new function in the interface and vtable in the correct position. In my opinion this is not a "BASIC"-Solution.
PureBasic support objects, sadly it doesn't have a "Basic-Style" method to create one. Something is missing here.
PureBasic support objects, sadly it doesn't have a "Basic-Style" method to create one. Something is missing here.
Re: a\\func(...) as shortcut for a\func(a,...)
+1
The interface solution is o.k. but You need a pre-compiler to make it work seamless.
I tried to do a project with it natively but You end up typing 24/7;-)
Too much overhead.
The interface solution is o.k. but You need a pre-compiler to make it work seamless.
I tried to do a project with it natively but You end up typing 24/7;-)
Too much overhead.