Simon Knight wrote: ↑Thu Jul 18, 2024 9:05 pm
So it seems that Point defines a special form of List i.e. inherits from List (object?) and overrides index processing?
I find it slightly strange to use an operator in a variable definition. However I see that Path, and Image are used in a similar way i.e.complex variable type definitions. The language reference needs fleshing out.
Perhaps this is what the following quote from the dictionary means
Note: In a subsequent update you will be able to define record types (named collections of values - like structs in C) and handler types (allowing dynamic handler calls through a variable - like function pointers in C).
Hard going for a Xtalk programmer!
I think the 'point' syntax is probably a type defined in a language module (there's a third type of LCB extension type besides widget and library)
I think it's this one "com.livecode.canvas".
But yes a Point type is basically just an array with two elements, the x,y coordinate numbers.
'Path' type is basically an aliased string type, 'Image' type just an alias of Data byte stream type
Last I checked you don't necessarily even need to provide an 'as variable-type', compiler will do some type inference.
I know in the past I've just used stuff like:
instead of 'variable tMySCGPathString as Path' and it compiled fine. Probably not the best practice to do this.
You can also allow a variable to be entirely undefined with 'optional any':
Code: Select all
variable tNotSureWhatType as optional any
The 'optional' means this variable could contain 'nothing' (undefined / null ) and the 'any' means it could store an ObjCId or it could be a unsigned integer we aren't sure what we're going to be putting in there.
Structs are possible by using Foreign Type definition strings, sort of like the way the Foreign Function binding strings are if you've seen any of that, which is not very intuitive, but it is a way to declare Record / Structs with fields of various value types (Pointer, Unsigned Integer, etc.). There's a chart somewhere, maybe in the "Extending ..." guide.
You can also use type declarations to make 'type aliases, which is handy when you're dealing with a bunch of pointers to various objects in memory. You don't want to mix up your NSWindow with your NSWindowController, ya know? (trying to think of s better example...)