Procedures inside Structures
-
- Addict
- Posts: 1371
- Joined: Wed Nov 12, 2008 5:01 pm
- Location: Russia
Re: Procedures inside Structures
It is a pity that it has not yet been added to PB.
Re: Procedures inside Structures
You could add the address of a function to a structure and call it, but I guess you already know this and you want to call it directly, like
?
Code: Select all
MyVar\MyFunc()
PureBasic 6.03 Beta 4/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
-
- Addict
- Posts: 1371
- Joined: Wed Nov 12, 2008 5:01 pm
- Location: Russia
Re: Procedures inside Structures
Is it a "dirty" method. It is easy to make a mistake by specifying the address of another procedure.
In addition, the procedure does not have native access to the fields of the structure.
The procedure must be inline in the structure and there must be no name collision.
In addition, the procedure does not have native access to the fields of the structure.
The procedure must be inline in the structure and there must be no name collision.
Code: Select all
Structure Test
x.l
s.s
Mutex.i
Procedure.s Proc(p1, p2) ; Regular procedure in a structure.
x = p1 * p2
ProcedureReturn s
EndProcedure
Procedure Test() ; Called automatically when a structure is created (constructor).
x = 10
s = "1234"
Mutex = CreateMutex()
EndProcedure
Procedure ~Test() ; Called automatically when the structure is freed (destructor).
x = 0
s = ""
If Mutex
FreeMutex(Mutex)
EndIf
EndProcedure
EndStructure
Procedure Proc() ; There is no name collision with a procedure in a structure.
x.Test
Debug x\Proc(1, 2) ; The result is "1234".
EndProcedure
Proc()
Re: Procedures inside Structures
I just saw that this is not a new thread and read the first posts. Why not use the prototype variant? Because the procedure itself is declared outside?
PureBasic 6.03 Beta 4/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
Re: Procedures inside Structures
May be you should watch your wording because it looks very aggressive to me.
Re: Procedures inside Structures
I read it as a sign of personal disappointment and disillusion.
Still tiny hope left ;
The language can use a bit more polish her and there. Still useful the way it is (otherwise I wouldn't be here, same as mr Russian I guess), just a less than optimal dev experience in certain cases. It is KISS, but doing that makes its use complex or code bloated in certain scenarios.
Btw this feature would make custom gadgets also more manageable.
Still tiny hope left ;
The language can use a bit more polish her and there. Still useful the way it is (otherwise I wouldn't be here, same as mr Russian I guess), just a less than optimal dev experience in certain cases. It is KISS, but doing that makes its use complex or code bloated in certain scenarios.
Btw this feature would make custom gadgets also more manageable.
-
- Addict
- Posts: 1371
- Joined: Wed Nov 12, 2008 5:01 pm
- Location: Russia
Re: Procedures inside Structures
Re: Procedures inside Structures
I use prototypes-in-structure for simple objects. I don't think it supports nested or structure unions.
I would not put this high on my What's Next PB list.
+ Fast strings
+ Static lib creation
+ Import C libs
+ Unsigned types (to support C libs)
+...
I would not put this high on my What's Next PB list.
+ Fast strings
+ Static lib creation
+ Import C libs
+ Unsigned types (to support C libs)
+...
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum