SetObject (Subsystem function): Difference between revisions
m (1 revision) |
m (move nowiki tag) |
||
(5 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
{{Template:Subsystem:SetObject subtitle}} | {{Template:Subsystem:SetObject subtitle}} | ||
The <var>SetObject</var> method makes a given object available with a specified name to the | The <var>SetObject</var> method makes a given object available with a specified name to the subsystem identified by the <var>Subsystem</var> method object. An object made thus available is known as a [[Subsystem_class#System-wide_objects|"system-wide object"]]. | ||
==Syntax== | ==Syntax== | ||
{{Template:Subsystem:SetObject syntax}} | {{Template:Subsystem:SetObject syntax}} | ||
===Syntax terms=== | ===Syntax terms=== | ||
<table class="syntaxTable"> | <table class="syntaxTable"> | ||
<tr><th>%gen</th><td>The new generation number associated with name. This is a positive integer (set to 1 the first time the method succeeds) that increases by one each time the name object is updated. <var class="term">gen</var> is set to 0 if the method encounters a problem or if <var class="term">testGen</var> differs from the current generation number of name. | <tr><th>%gen</th> | ||
<td>The new generation number associated with name. This is a positive integer (set to 1 the first time the method succeeds) that increases by one each time the name object is updated. <var class="term">gen</var> is set to 0 if the method encounters a problem or if <var class="term">testGen</var> differs from the current generation number of name. | |||
<p>All other errors result in request cancellation.</p></td></tr> | <p>All other errors result in request cancellation.</p></td></tr> | ||
<tr><th><var>%(Subsystem)</var></th> | |||
<td>The class name in parentheses denotes a [[Notation conventions for methods#Shared methods | <tr><th><var class="nobr">%(Subsystem)</var></th> | ||
<td>The class name in parentheses denotes a [[Notation conventions for methods#Shared methods|shared]] method. <var>SetObject</var> can also be invoked via a <var>Subsystem</var> object variable, which may be <var>null</var>.</td></tr> | |||
<tr><th>name</th> | <tr><th>name</th> | ||
<td>The string name by which the system-wide object is identified.</td></tr> | <td>The string name by which the system-wide object is identified.</td></tr> | ||
<tr><th>object</th> | <tr><th>object</th> | ||
<td>The object variable that becomes the current system-wide object. The object referenced by <var class="term">object</var> must be [[Copying objects|"deep copyable"]] | <td>The object variable that becomes the current system-wide object. The object referenced by <var class="term">object</var> must be [[Copying objects|"deep copyable"]].</td></tr> | ||
<tr><th>testGen</th> | <tr><th>testGen</th> | ||
<td>An optional argument, this is an integer that is compared to the current generation number of name. If the values differ, <var>SetObject</var> fails to replace <var class="term"> | <td>An optional argument, this is an integer that is compared to the current generation number of name. If the values differ, <var>SetObject</var> fails to replace <var class="term">object</var>, and it returns a 0 value.</td></tr> | ||
</table> | </table> | ||
==Examples== | ==Examples== | ||
The following example shows how the generation number can be used to make sure that you do not update an object that someone else updated after you got your copy. | The following example shows how the generation number can be used to make sure that you do not update an object that someone else updated after you got your copy. | ||
<p class="code" | <p class="code">%myObj is object myClass | ||
... | ... | ||
retry: | retry: | ||
%gen = %(system): | %gen = %(system):[[GetObject_(Subsystem_function)|getObject]]('FOO', %myObj) | ||
... fiddle with the object | ... fiddle with the object | ||
* Now try to update it | <nowiki>* Now try to update it | ||
if not %(system):setObject('FOO', %myObj, %gen) then | if not %(system):setObject('FOO', %myObj, %gen) then | ||
* Someone else changed it, let's see what they did | * Someone else changed it, let's see what they did | ||
Line 31: | Line 37: | ||
end if | end if | ||
</nowiki></p> | </nowiki></p> | ||
In this case, when you try to update FOO, FOO's generation is compared with %gen. If the generation number changed, the <var>SetObject</var> call does not succeed, and 0 is returned. | In this case, when you try to update <code>FOO</code>, <code>FOO</code>'s generation is compared with <code>%gen</code>. If the generation number changed, the <var>SetObject</var> call does not succeed, and 0 is returned. | ||
==See also== | ==See also== | ||
{{Template:Subsystem:SetObject footer}} | {{Template:Subsystem:SetObject footer}} |
Latest revision as of 23:52, 19 February 2015
Set a subsystem object (Subsystem class)
The SetObject method makes a given object available with a specified name to the subsystem identified by the Subsystem method object. An object made thus available is known as a "system-wide object".
Syntax
[%gen =] %(Subsystem):SetObject( name, object, [testGen])
Syntax terms
%gen | The new generation number associated with name. This is a positive integer (set to 1 the first time the method succeeds) that increases by one each time the name object is updated. gen is set to 0 if the method encounters a problem or if testGen differs from the current generation number of name.
All other errors result in request cancellation. |
---|---|
%(Subsystem) | The class name in parentheses denotes a shared method. SetObject can also be invoked via a Subsystem object variable, which may be null. |
name | The string name by which the system-wide object is identified. |
object | The object variable that becomes the current system-wide object. The object referenced by object must be "deep copyable". |
testGen | An optional argument, this is an integer that is compared to the current generation number of name. If the values differ, SetObject fails to replace object, and it returns a 0 value. |
Examples
The following example shows how the generation number can be used to make sure that you do not update an object that someone else updated after you got your copy.
%myObj is object myClass ... retry: %gen = %(system):getObject('FOO', %myObj) ... fiddle with the object * Now try to update it if not %(system):setObject('FOO', %myObj, %gen) then * Someone else changed it, let's see what they did jump to retry end if
In this case, when you try to update FOO
, FOO
's generation is compared with %gen
. If the generation number changed, the SetObject call does not succeed, and 0 is returned.