Procedures inside Structures
-
- Addict
- Posts: 1516
- 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()
Good morning, that's a nice tnetennba!
PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
-
- Addict
- Posts: 1516
- 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?
Good morning, that's a nice tnetennba!
PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
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: 1516
- Joined: Wed Nov 12, 2008 5:01 pm
- Location: Russia
Re: Procedures inside Structures
Sorry, I use google-translator and this is probably an imperfect translation into english.Fred wrote: Sat Jun 10, 2023 4:32 pmMay be you should watch your wording because it looks very aggressive to me.
I didn't mean anything bad.
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