Adding extra properties to objects

Something you want to see in a LiveCode product? Want a new forum set up for a specific topic? Talk about it here.

Moderator: Klaus

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10081
Joined: Fri Feb 19, 2010 10:17 am

Adding extra properties to objects

Post by richmond62 » Sun May 11, 2014 9:05 am

It would be wonderful if existing objects (button, fields and so on) could have their capabilities extended by allowing end users to
add additional properties to them.

This ability (to add extra properties to objects) should, preferably, be possible from within Livecode rather
than having recourse to another programming language such as C++.
LC_gadfly_banana.png

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10081
Joined: Fri Feb 19, 2010 10:17 am

Re: Adding extra properties to objects

Post by richmond62 » Sun May 11, 2014 9:52 am

I do wonder if there is also not a need for a new property inspector where ALL the properties
of an object are visible.

After all, if one looks up 'Button' in the dictionary there is no list of all
of a button's properties. This is a lack of transparency; and transparency
is a feature of most Open Source projects.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10081
Joined: Fri Feb 19, 2010 10:17 am

Re: Adding extra properties to objects

Post by richmond62 » Sun May 11, 2014 10:08 am

props.png
That is NOT an advance.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10081
Joined: Fri Feb 19, 2010 10:17 am

Re: Adding extra properties to objects

Post by richmond62 » Sun May 11, 2014 10:23 am

This is rather useless as I cannot work out how to get a list of an object's properties alongside the names of those properties:
The attachment propalopalop.png is no longer available
The attachment propFlop.png is no longer available
Attachments
propz.zip
The stack in the pictures
(695 Bytes) Downloaded 147 times

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10081
Joined: Fri Feb 19, 2010 10:17 am

Re: Adding extra properties to objects

Post by richmond62 » Sun May 11, 2014 10:24 am

And while the above may be extended to list all an object's props, and even adjust them; what it does not
do is allow one to add extra properties.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10081
Joined: Fri Feb 19, 2010 10:17 am

Re: Adding extra properties to objects

Post by richmond62 » Sun May 11, 2014 10:38 am

What tripped off this idea was an attempt to set the htmlText of a label;
which is not possible as a label does not have that property.

Now at that point the obvious reason to why a label does not have that
property is that whoever put together LABELs in Metacard or
Livecode either didn't think that would be a useful property, or it
didn't even cross their mind.

Expecting the designers of Livecode to think about all eventual uses and requirements
is asking way too much!

Therefore, were objects hackable in such a way that their properties could be extended
when end users found that they had a requirement for a property that did not exist in an object
as it came in Livecode, that would be a great service, AND . . .

there could also be a way where, once an end user has added a property to an object it could
be submitted back to RunRev for consideration as to whether that should become a regular
property of that object in the next version of Livecode.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10081
Joined: Fri Feb 19, 2010 10:17 am

Re: Adding extra properties to objects

Post by richmond62 » Sun May 11, 2014 10:43 am

propsBN.png
propsSCbn.png
Thanks to Bernd Niggemann!

Not documented at all.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10081
Joined: Fri Feb 19, 2010 10:17 am

Re: Adding extra properties to objects

Post by richmond62 » Sun May 11, 2014 10:47 am

propz2.zip
Altered stack.
(1.13 KiB) Downloaded 169 times

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10043
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Adding extra properties to objects

Post by FourthWorld » Sun May 11, 2014 3:39 pm

See customKeys, getProp, and setProp.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7389
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Adding extra properties to objects

Post by jacque » Sun May 11, 2014 6:57 pm

richmond62 wrote:And while the above may be extended to list all an object's props, and even adjust them; what it does not
do is allow one to add extra properties.
As mentioned, getProp and setProp allows you to create your own virtual properties, as long as they don't require non-existent engine behavior. But the only way to change the engine itself is to revise the C++ code that drives it. How else could you add something like an html property to a label, when the engine itself must draw that label? When you are dealing with LC primitives, you have to change the engine code.

RR has provided a way to do that, but you must use the language that the engine understands. How else could it be possible?
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10081
Joined: Fri Feb 19, 2010 10:17 am

Re: Adding extra properties to objects

Post by richmond62 » Sun May 11, 2014 9:08 pm

"RR has provided a way to do that"

Well, that's a start.

However, if the engine understands C++
and not Livecode, there must be an interpreter
somewhere in between the engine and Livecode . . . ?

I would be very grateful if you could post where
RR has provided that way.

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7389
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Adding extra properties to objects

Post by jacque » Mon May 12, 2014 7:13 am

I probably wasn't clear. There are two ways to enhance the language. The first is to create your own virtual properties using setProp/getProp. Those of course can only use syntax that is already defined in the engine; that is, the syntax you find in the dictionary. These virtual properties apply only to your own stacks or apps; they are part of your scripts.

The second way is to actually change the engine we know as LiveCode. These new properties would alter the engine behavior for everyone, they become part of the LC build. If you want to add properties to native objects (the ones I called primitives, the objects in the tools palette) then you have to write engine code, and that has to be in C++. That's what the RR team and the open source contributors do.

There is no "interpreter" per se, the engine runs the code it is written in, and your scripts call the code that has been defined in the engine.

Virtual properties are pretty cool. You can define anything as a "property" by using a setProp handler. If you do not pass the setProp message, no actual custom property is assigned to the object, but you can define the behavior to act as though it were a built-in one. If someone else doesn't provide an example first, I'll try to do it tomorrow; it's late here right now.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10081
Joined: Fri Feb 19, 2010 10:17 am

Re: Adding extra properties to objects

Post by richmond62 » Mon May 12, 2014 12:09 pm

I am aware that that involves C++.

Does that mean one has to work on the source from the Git Hub?

DarScott
Posts: 227
Joined: Fri Jul 28, 2006 12:23 am
Contact:

Re: Adding extra properties to objects

Post by DarScott » Wed May 14, 2014 12:04 am

I'm not following. If getProp and setProp work, then why add it to the engine?

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7389
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Adding extra properties to objects

Post by jacque » Wed May 14, 2014 5:50 am

richmond62 wrote:Does that mean one has to work on the source from the Git Hub?
Yes, generally, though it isn't strictly required I don't think. You could download the source code and not resubmit to GitHub. I'm not sure if that's considered ethical since we're supposed to give back to the community, but you could do it.

I found an example of a virtual property in one of my stacks. This is a simple version of an on/off switch button that also changes an associated label field:

Code: Select all

setprop switchIcon pBool  
  if pBool then
    set the icon of the target to 1557 -- on
    put 0 into tBlendLevel
  else
    set the icon of the target to 1558 -- off
    put 60 into tBlendLevel
  end if
  put the short name of the target && "icon" into tIcon
  if there is an img tIcon then set the blendlevel of img tIcon to tBlendLevel
  put "lbl-" & the short name of the target into tLbl
  replace space with empty in tLbl
  if there is a fld tLbl then set the blendlevel of fld tLbl to tBlendLevel
end switchIcon
Now when I want to change the appearance on a button, I can say:

set the switchIcon of btn 2 to true

You can use getProp similarly, which allows syntax like the built-in functions; you can say "the something" instead of "something()".
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Post Reply