Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit 9530c1f

Browse filesBrowse files
committed
[[ Widget ]] Add ability to specify property set when accessing properties
This patch adds the syntax `property <prop> of set <set> of <object>` to specify which object property set to fetch a value from.
1 parent e2d9abe commit 9530c1f
Copy full SHA for 9530c1f

File tree

5 files changed

+74
-31
lines changed
Filter options

5 files changed

+74
-31
lines changed
+13Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# LiveCode Builder Host Library
2+
## Engine library
3+
4+
A new syntax variant `property <propertyName> of set <setName> of <object>` has
5+
been added to allow access to values from custom property sets.
6+
7+
For example to save and restore the rect of a widget to a custom property set:
8+
// save
9+
set property "savedRect" of set "cGeometry" of my script object to my rect
10+
11+
// restore
12+
set property "rect" of my script object to property "savedRect" of set "cGeometry" of my script object
13+

‎engine/src/engine.lcb

Copy file name to clipboardExpand all lines: engine/src/engine.lcb
+13Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ public foreign handler MCEngineEvalScriptObjectExists(in pObject as ScriptObject
4646
public foreign handler MCEngineEvalScriptObjectDoesNotExist(in pObject as ScriptObject, out rExists as CBool) returns nothing binds to "<builtin>"
4747
public foreign handler MCEngineExecGetPropertyOfScriptObject(in pProperty as String, in pObject as ScriptObject, out rValue as any) returns nothing binds to "<builtin>"
4848
public foreign handler MCEngineExecSetPropertyOfScriptObject(in pValue as any, in pProperty as String, in pObject as ScriptObject) returns nothing binds to "<builtin>"
49+
public foreign handler MCEngineExecGetPropertyOfSetOfScriptObject(in pProperty as String, in pSet as String, in pObject as ScriptObject, out rValue as any) returns nothing binds to "<builtin>"
50+
public foreign handler MCEngineExecSetPropertyOfSetOfScriptObject(in pValue as any, in pProperty as String, in pSet as String, in pObject as ScriptObject) returns nothing binds to "<builtin>"
4951
public foreign handler MCEngineEvalOwnerOfScriptObject(in pObject as ScriptObject, out rParent as ScriptObject) returns nothing binds to "<builtin>"
5052
public foreign handler MCEngineEvalChildrenOfScriptObject(in pObject as ScriptObject, out rChildren as List) returns nothing binds to "<builtin>"
5153
public foreign handler MCEngineExecSendToScriptObject(in pIsFunction as CBool, in pMessage as String, in pTarget as ScriptObject) returns optional any binds to "<builtin>"
@@ -181,6 +183,7 @@ end syntax
181183
/**
182184
Summary: The property of a script object.
183185
Property: The name of the property to manipulate
186+
Set: The name of the custom property set to access
184187
Object: An expression that evaluates to a <ScriptObject>.
185188

186189

@@ -194,6 +197,9 @@ Example:
194197
set property "invisible" of the result to true
195198
get property "script" of my script object
196199

200+
Example:
201+
get property "customProp" of set "cMyCustomPropertySet" of my script object
202+
197203
Description:
198204
Use to manipulate properties of a script object.
199205

@@ -212,6 +218,13 @@ begin
212218
MCEngineExecSetPropertyOfScriptObject(input, Property, Object)
213219
end syntax
214220

221+
syntax PropertyOfSetOfScriptObject is prefix operator with property precedence
222+
"property" <Property: Expression> "of" "set" <Set: Expression> "of" <Object: Expression>
223+
begin
224+
MCEngineExecGetPropertyOfSetOfScriptObject(Property, Set, Object, output)
225+
MCEngineExecSetPropertyOfSetOfScriptObject(input, Property, Set, Object)
226+
end syntax
227+
215228
/**
216229
Summary: Get the parent object of a script object.
217230
Object: An expression that evaluates to a <ScriptObject>.

‎engine/src/module-engine.cpp

Copy file name to clipboardExpand all lines: engine/src/module-engine.cpp
+43-26Lines changed: 43 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ bool MCEngineEvalObjectOfScriptObject(MCScriptObjectRef p_object, MCObject *&r_o
267267
return true;
268268
}
269269

270-
MCValueRef MCEngineGetPropertyOfObject(MCExecContext &ctxt, MCStringRef p_property, MCObject *p_object, uint32_t p_part_id)
270+
MCValueRef MCEngineGetPropertyOfObject(MCExecContext &ctxt, MCStringRef p_set, MCStringRef p_property, MCObject *p_object, uint32_t p_part_id)
271271
{
272272
Properties t_prop;
273273
t_prop = parse_property_name(p_property);
@@ -276,11 +276,14 @@ MCValueRef MCEngineGetPropertyOfObject(MCExecContext &ctxt, MCStringRef p_proper
276276

277277
if (t_prop == P_CUSTOM)
278278
{
279-
MCNewAutoNameRef t_propset_name, t_propset_key;
280-
t_propset_name = p_object -> getdefaultpropsetname();
281-
if (!MCNameCreate(p_property, &t_propset_key))
279+
MCNewAutoNameRef t_set_name, t_prop_name;
280+
if (MCStringIsEmpty(p_set))
281+
t_set_name = p_object -> getdefaultpropsetname();
282+
else if (!MCNameCreate(p_set, &t_set_name))
282283
return nil;
283-
p_object -> getcustomprop(ctxt, *t_propset_name, *t_propset_key, nil, t_value);
284+
if (!MCNameCreate(p_property, &t_prop_name))
285+
return nil;
286+
p_object -> getcustomprop(ctxt, *t_set_name, *t_prop_name, nil, t_value);
284287
}
285288
else
286289
p_object -> getprop(ctxt, p_part_id, t_prop, nil, False, t_value);
@@ -301,7 +304,7 @@ MCValueRef MCEngineGetPropertyOfObject(MCExecContext &ctxt, MCStringRef p_proper
301304
return t_value_ref;
302305
}
303306

304-
extern "C" MC_DLLEXPORT_DEF void MCEngineExecGetPropertyOfScriptObject(MCStringRef p_property, MCScriptObjectRef p_object, MCValueRef& r_value)
307+
extern "C" MC_DLLEXPORT_DEF void MCEngineExecGetPropertyOfSetOfScriptObject(MCStringRef p_property, MCStringRef p_set, MCScriptObjectRef p_object, MCValueRef& r_value)
305308
{
306309
if (!MCEngineEnsureScriptObjectAccessIsAllowed())
307310
{
@@ -318,11 +321,16 @@ extern "C" MC_DLLEXPORT_DEF void MCEngineExecGetPropertyOfScriptObject(MCStringR
318321
MCExecContext ctxt(MCdefaultstackptr, nil, nil);
319322

320323
// AL-2015-07-24: [[ Bug 15630 ]] Syntax binding dictates value returned as out parameter rather than directly
321-
r_value = MCEngineGetPropertyOfObject(ctxt, p_property, t_object, t_part_id);
324+
r_value = MCEngineGetPropertyOfObject(ctxt, p_set, p_property, t_object, t_part_id);
325+
}
326+
327+
extern "C" MC_DLLEXPORT_DEF void MCEngineExecGetPropertyOfScriptObject(MCStringRef p_property, MCScriptObjectRef p_object, MCValueRef& r_value)
328+
{
329+
MCEngineExecGetPropertyOfSetOfScriptObject(p_property, kMCEmptyString, p_object, r_value);
322330
}
323331

324332
// IM-2015-02-23: [[ WidgetPopup ]] Factored-out function for setting the named property of an object to a value.
325-
void MCEngineSetPropertyOfObject(MCExecContext &ctxt, MCStringRef p_property, MCObject *p_object, uint32_t p_part_id, MCValueRef p_value)
333+
void MCEngineSetPropertyOfObject(MCExecContext &ctxt, MCStringRef p_set, MCStringRef p_property, MCObject *p_object, uint32_t p_part_id, MCValueRef p_value)
326334
{
327335
MCValueRef t_value_copy;
328336
t_value_copy = MCValueRetain(p_value);
@@ -343,14 +351,20 @@ void MCEngineSetPropertyOfObject(MCExecContext &ctxt, MCStringRef p_property, MC
343351

344352
if (t_prop == P_CUSTOM)
345353
{
346-
MCNewAutoNameRef t_propset_name, t_propset_key;
347-
t_propset_name = p_object -> getdefaultpropsetname();
348-
if (!MCNameCreate(p_property, &t_propset_key))
349-
{
350-
MCValueRelease(t_value_copy);
351-
return;
352-
}
353-
p_object -> setcustomprop(ctxt, *t_propset_name, *t_propset_key, nil, t_value);
354+
MCNewAutoNameRef t_set_name, t_prop_name;
355+
if (MCStringIsEmpty(p_set))
356+
t_set_name = p_object -> getdefaultpropsetname();
357+
else if (!MCNameCreate(p_set, &t_set_name))
358+
{
359+
MCValueRelease(t_value_copy);
360+
return;
361+
}
362+
if (!MCNameCreate(p_property, &t_prop_name))
363+
{
364+
MCValueRelease(t_value_copy);
365+
return;
366+
}
367+
p_object -> setcustomprop(ctxt, *t_set_name, *t_prop_name, nil, t_value);
354368
}
355369
else
356370
p_object -> setprop(ctxt, p_part_id, t_prop, nil, False, t_value);
@@ -362,21 +376,26 @@ void MCEngineSetPropertyOfObject(MCExecContext &ctxt, MCStringRef p_property, MC
362376
}
363377
}
364378

365-
extern "C" MC_DLLEXPORT_DEF void MCEngineExecSetPropertyOfScriptObject(MCValueRef p_value, MCStringRef p_property, MCScriptObjectRef p_object)
379+
extern "C" MC_DLLEXPORT_DEF void MCEngineExecSetPropertyOfSetOfScriptObject(MCValueRef p_value, MCStringRef p_property, MCStringRef p_set, MCScriptObjectRef p_object)
366380
{
367-
if (!MCEngineEnsureScriptObjectAccessIsAllowed())
368-
{
369-
return;
370-
}
371-
381+
if (!MCEngineEnsureScriptObjectAccessIsAllowed())
382+
{
383+
return;
384+
}
385+
372386
MCObject *t_object;
373387
uint32_t t_part_id;
374388
if (!MCEngineEvalObjectOfScriptObject(p_object, t_object, t_part_id))
375389
return;
376390

377-
MCExecContext ctxt(MCdefaultstackptr, nil, nil);
391+
MCExecContext ctxt(MCdefaultstackptr, nil, nil);
392+
393+
MCEngineSetPropertyOfObject(ctxt, p_set, p_property, t_object, t_part_id, p_value);
394+
}
378395

379-
MCEngineSetPropertyOfObject(ctxt, p_property, t_object, t_part_id, p_value);
396+
extern "C" MC_DLLEXPORT_DEF void MCEngineExecSetPropertyOfScriptObject(MCValueRef p_value, MCStringRef p_property, MCScriptObjectRef p_object)
397+
{
398+
MCEngineExecSetPropertyOfSetOfScriptObject(p_value, p_property, kMCEmptyString, p_object);
380399
}
381400

382401
extern "C" MC_DLLEXPORT_DEF void MCEngineEvalOwnerOfScriptObject(MCScriptObjectRef p_object, MCScriptObjectRef &r_owner)
@@ -589,9 +608,7 @@ void MCEngineDoPostToObjectWithArguments(MCStringRef p_message, MCObject *p_obje
589608

590609
MCExecContext ctxt(MCdefaultstackptr, nil, nil);
591610
MCParameter *t_params;
592-
MCValueRef t_result;
593611
t_params = nil;
594-
t_result = nil;
595612

596613
if (!MCEngineConvertToScriptParameters(ctxt, p_arguments, t_params))
597614
return;

‎engine/src/objectprops.cpp

Copy file name to clipboardExpand all lines: engine/src/objectprops.cpp
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ Exec_stat MCObject::sendgetprop(MCExecContext& ctxt, MCNameRef p_set_name, MCNam
279279
t_getprop_name = p_set_name, t_param_name = p_prop_name;
280280

281281
Exec_stat t_stat = ES_NOT_HANDLED;
282-
if (!MClockmessages && (ctxt . GetObject() != this || !ctxt . GetHandler() -> hasname(t_getprop_name)))
282+
if (!MClockmessages && (ctxt . GetObject() != this || ctxt.GetHandler() == nil || !ctxt . GetHandler() -> hasname(t_getprop_name)))
283283
{
284284
MCParameter p1;
285285
p1.setvalueref_argument(t_param_name);

‎engine/src/widget-popup.cpp

Copy file name to clipboardExpand all lines: engine/src/widget-popup.cpp
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@
5757

5858
////////////////////////////////////////////////////////////////////////////////
5959

60-
extern MCValueRef MCEngineGetPropertyOfObject(MCExecContext &ctxt, MCStringRef p_property, MCObject *p_object, uint32_t p_part_id);
61-
extern void MCEngineSetPropertyOfObject(MCExecContext &ctxt, MCStringRef p_property, MCObject *p_object, uint32_t p_part_id, MCValueRef p_value);
60+
extern MCValueRef MCEngineGetPropertyOfObject(MCExecContext &ctxt, MCStringRef p_set, MCStringRef p_property, MCObject *p_object, uint32_t p_part_id);
61+
extern void MCEngineSetPropertyOfObject(MCExecContext &ctxt, MCStringRef p_set, MCStringRef p_property, MCObject *p_object, uint32_t p_part_id, MCValueRef p_value);
6262

6363
class MCWidgetPopup: public MCStack
6464
{
@@ -189,7 +189,7 @@ class MCWidgetPopup: public MCStack
189189

190190
while (MCArrayIterate(p_properties, t_iter, t_key, t_value))
191191
{
192-
MCEngineSetPropertyOfObject(ctxt, MCNameGetString(t_key), m_widget, 0, t_value);
192+
MCEngineSetPropertyOfObject(ctxt, kMCEmptyString, MCNameGetString(t_key), m_widget, 0, t_value);
193193
if (MCErrorIsPending())
194194
return false;
195195
}
@@ -231,7 +231,7 @@ class MCWidgetPopup: public MCStack
231231
{
232232
MCExecContext ctxt(MCdefaultstackptr, nil, nil);
233233
MCAutoValueRef t_value;
234-
t_value = MCEngineGetPropertyOfObject(ctxt, MCSTR("preferredSize"), m_widget, 0);
234+
t_value = MCEngineGetPropertyOfObject(ctxt, kMCEmptyString, MCSTR("preferredSize"), m_widget, 0);
235235
if (MCErrorIsPending())
236236
return false;
237237

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.