bmx-ng / bcc

A next-generation bcc parser for BlitzMax
zlib License
33 stars 12 forks source link

Structs: Return VarPtr Self - not possible #598

Open GWRon opened 2 years ago

GWRon commented 2 years ago
SuperStrict
Framework Brl.StandardIO

Struct STest
  Field X:Int

  Method Add:STest Ptr(value:Int)
    X :+ value
    Return Varptr Self
  End Method
End Struct

lets bcc spit out: Compile Error: Subexpression for 'Varptr' must be a variable or an element of an array, pointer or string.

So how to return a "reference" (pointer) of a struct?

"idea" is to enable structs to daisy chain methods:

myStruct.Add(x).Subtract(y).Multiply(z) 'altering the original myStruct with each Method call
GWRon commented 1 year ago

Pointers to structs are legible:

SuperStrict
Framework Brl.StandardIO

Struct STest
  Field X:Int

End Struct

Local s:STest
Local sP:STest Ptr = varptr s
sP.X = 20

print s.X

so it should be valid for "varptr self" (inside of a struct) too.