Page 3 of 3

Re: Procedures inside Structures

Posted: Sat Jun 10, 2023 3:10 pm
by User_Russian
It is a pity that it has not yet been added to PB.

Re: Procedures inside Structures

Posted: Sat Jun 10, 2023 3:17 pm
by jacdelad
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()
?

Re: Procedures inside Structures

Posted: Sat Jun 10, 2023 3:37 pm
by User_Russian
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.

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

Posted: Sat Jun 10, 2023 4:20 pm
by jacdelad
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?

Re: Procedures inside Structures

Posted: Sat Jun 10, 2023 4:32 pm
by Fred
User_Russian wrote: Sat Jun 10, 2023 3:10 pm It is a pity that it has not yet been added to PB.
May be you should watch your wording because it looks very aggressive to me.

Re: Procedures inside Structures

Posted: Sat Jun 10, 2023 4:57 pm
by Rinzwind
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.

Re: Procedures inside Structures

Posted: Sat Jun 10, 2023 7:16 pm
by User_Russian
Fred wrote: Sat Jun 10, 2023 4:32 pm
User_Russian wrote: Sat Jun 10, 2023 3:10 pm It is a pity that it has not yet been added to PB.
May be you should watch your wording because it looks very aggressive to me.
Sorry, I use google-translator and this is probably an imperfect translation into english.
I didn't mean anything bad.

Re: Procedures inside Structures

Posted: Sun Jun 11, 2023 4:08 pm
by skywalk
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)
+...