The Point type

LiveCode Builder is a language for extending LiveCode's capabilities, creating new object types as Widgets, and libraries that access lower-level APIs in OSes, applications, and DLLs.

Moderators: LCMark, LCfraser

Post Reply
Simon Knight
Posts: 916
Joined: Wed Nov 04, 2009 11:41 am

The Point type

Post by Simon Knight » Thu Jul 18, 2024 8:48 am

I am reviewing the LCB file that Bernd kindly published in order to try and get some understanding of how a widget is created.

In the code the type Point is used e.g.

Code: Select all

  private variable mCenterPoint as Point
Where is this type documented ?
Looking in the LCB dictionary the following types are defined :
The range of core types is relatively small, comprising the following:

nothing: the single value nothing
Boolean: one of true or false
Integer: any integral numeric value (size limitations apply)
Real: any numeric value (size and accuracy limitations apply)
Number: any integer or real value
String: a sequence of UTF-16 code units
Data: a sequence of bytes
List: a sequence of any values
Array: a mapping from strings to values
any: a value of any type
So where does Point come from ?

I note that the TypeDefinition allows the definition of an alias to a core type but I can not see it being used in the code.
best wishes
Skids

stam
Posts: 3003
Joined: Sun Jun 04, 2006 9:39 pm

Re: The Point type

Post by stam » Thu Jul 18, 2024 2:08 pm

Sadly the poor state of LCB documentation is what stopped this from every being more widely used...
Anyone new to LCB and wanting to pick this up cannot do so without practically Herculean efforts, and not everyone has the time to dedicate to this sadly...

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4129
Joined: Sun Jan 07, 2007 9:12 pm

Re: The Point type

Post by bn » Thu Jul 18, 2024 4:40 pm

Hi Simon,

Simon Knight wrote:
Thu Jul 18, 2024 8:48 am
In the code the type Point is used e.g.

Code: Select all

  private variable mCenterPoint as Point
Where is this type documented ?
--
--
So where does Point come from ?
I do not know about Types.

However if you look "Point" up in LCB dictionary its "type" is "operator" and it is a list of 2 items; the first is the x-value, the second the y-value.

Code: Select all

variable tPoint as Point
put point [50, 100] into tPoint
So declaring a variable as "point" sets the format of the variable to a list with 2 items. (Creates a new point value.)
It has as properties

Code: Select all

the x of tPoint
the y of tPoint
I take it as it is used and it is very handy to use this defined variable.
Also it is probably a lot easier to compile since there is a lot less guesswork.

I realise that this does not answer fully your question but this is all I can offer.

Kind regards
Bernd

Simon Knight
Posts: 916
Joined: Wed Nov 04, 2009 11:41 am

Re: The Point type

Post by Simon Knight » 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!
best wishes
Skids

PaulDaMacMan
Posts: 670
Joined: Wed Apr 24, 2013 4:53 pm
Contact:

Re: The Point type

Post by PaulDaMacMan » Fri Jul 26, 2024 7:24 am

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 neccisarly even need to provide an 'as variable-type' it will do some type inference.
I know in the past I've just used stuff like:

Code: Select all

variable tMySVGPathString
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 pointing 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...)
My GitHub Repos: https://github.com/PaulMcClernan/
Related YouTube Videos: PlayList

PaulDaMacMan
Posts: 670
Joined: Wed Apr 24, 2013 4:53 pm
Contact:

Re: The Point type

Post by PaulDaMacMan » Fri Jul 26, 2024 7:26 am

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:

Code: Select all

variable tMySVGPathString
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...)
My GitHub Repos: https://github.com/PaulMcClernan/
Related YouTube Videos: PlayList

PaulDaMacMan
Posts: 670
Joined: Wed Apr 24, 2013 4:53 pm
Contact:

Re: The Point type

Post by PaulDaMacMan » Fri Jul 26, 2024 7:36 am

Sorry for double post, had a Wifi issue.
My GitHub Repos: https://github.com/PaulMcClernan/
Related YouTube Videos: PlayList

PaulDaMacMan
Posts: 670
Joined: Wed Apr 24, 2013 4:53 pm
Contact:

Re: The Point type

Post by PaulDaMacMan » Fri Jul 26, 2024 8:27 am

Yes, that's where these types are defined in that canvas module, they're linked to internal engine stuff with FFI bindings.
The LCB source code for the language module is viewable here:
https://github.com/livecode/livecode/bl ... canvas.lcb.
My GitHub Repos: https://github.com/PaulMcClernan/
Related YouTube Videos: PlayList

Simon Knight
Posts: 916
Joined: Wed Nov 04, 2009 11:41 am

Re: The Point type

Post by Simon Knight » Fri Jul 26, 2024 10:18 am

Thanks Paul,

Given the recent announcement I'm "considering my position" as they say.
best wishes
Skids

PaulDaMacMan
Posts: 670
Joined: Wed Apr 24, 2013 4:53 pm
Contact:

Re: The Point type

Post by PaulDaMacMan » Fri Jul 26, 2024 6:11 pm

Simon Knight wrote:
Fri Jul 26, 2024 10:18 am
Thanks Paul,

Given the recent announcement I'm "considering my position" as they say.
I hear ya, understandable. Well I'll go back to my corner now. :P
My GitHub Repos: https://github.com/PaulMcClernan/
Related YouTube Videos: PlayList

Post Reply

Return to “LiveCode Builder”