diff options
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/Variable.cs')
-rw-r--r-- | OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/Variable.cs | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/Variable.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/Variable.cs index f68a941..a606465 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/Variable.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/Variable.cs | |||
@@ -43,6 +43,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.YieldProlog | |||
43 | bool ground(); | 43 | bool ground(); |
44 | } | 44 | } |
45 | 45 | ||
46 | /// <summary> | ||
47 | /// A Variable is passed to a function so that it can be unified with | ||
48 | /// value or another Variable. See getValue and unify for details. | ||
49 | /// </summary> | ||
46 | public class Variable : IUnifiable | 50 | public class Variable : IUnifiable |
47 | { | 51 | { |
48 | // Use _isBound separate from _value so that it can be bound to any value, | 52 | // Use _isBound separate from _value so that it can be bound to any value, |
@@ -50,6 +54,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.YieldProlog | |||
50 | private bool _isBound = false; | 54 | private bool _isBound = false; |
51 | private object _value; | 55 | private object _value; |
52 | 56 | ||
57 | /// <summary> | ||
58 | /// If this Variable is unbound, then just return this Variable. | ||
59 | /// Otherwise, if this has been bound to a value with unify, return the value. | ||
60 | /// If the bound value is another Variable, this follows the "variable chain" | ||
61 | /// to the end and returns the final value, or the final Variable if it is unbound. | ||
62 | /// For more details, see http://yieldprolog.sourceforge.net/tutorial1.html | ||
63 | /// </summary> | ||
64 | /// <returns></returns> | ||
53 | public object getValue() | 65 | public object getValue() |
54 | { | 66 | { |
55 | if (!_isBound) | 67 | if (!_isBound) |
@@ -68,6 +80,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.YieldProlog | |||
68 | return result; | 80 | return result; |
69 | } | 81 | } |
70 | 82 | ||
83 | /// <summary> | ||
84 | /// If this Variable is bound, then just call YP.unify to unify this with arg. | ||
85 | /// (Note that if arg is an unbound Variable, then YP.unify will bind it to | ||
86 | /// this Variable's value.) | ||
87 | /// Otherwise, bind this Variable to YP.getValue(arg) and yield once. After the | ||
88 | /// yield, return this Variable to the unbound state. | ||
89 | /// For more details, see http://yieldprolog.sourceforge.net/tutorial1.html | ||
90 | /// </summary> | ||
91 | /// <param name="arg"></param> | ||
92 | /// <returns></returns> | ||
71 | public IEnumerable<bool> unify(object arg) | 93 | public IEnumerable<bool> unify(object arg) |
72 | { | 94 | { |
73 | if (!_isBound) | 95 | if (!_isBound) |
@@ -92,12 +114,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.YieldProlog | |||
92 | } | 114 | } |
93 | else | 115 | else |
94 | { | 116 | { |
95 | // disable warning: don't see how we can code this differently short | 117 | // disable warning on l1, don't see how we can |
96 | // of rewriting the whole thing | 118 | // code this differently |
97 | #pragma warning disable 0168 | 119 | #pragma warning disable 0168 |
98 | foreach (bool l1 in YP.unify(this, arg)) | 120 | foreach (bool l1 in YP.unify(this, arg)) |
99 | yield return false; | 121 | yield return false; |
100 | #pragma warning restore 0168 | 122 | #pragma warning restore 0168 |
101 | } | 123 | } |
102 | } | 124 | } |
103 | 125 | ||
@@ -105,7 +127,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.YieldProlog | |||
105 | { | 127 | { |
106 | object value = getValue(); | 128 | object value = getValue(); |
107 | if (value == this) | 129 | if (value == this) |
108 | return "Variable"; | 130 | return "_Variable"; |
109 | else | 131 | else |
110 | return getValue().ToString(); | 132 | return getValue().ToString(); |
111 | } | 133 | } |