1
0
mirror of https://github.com/Ylianst/MeshAgent synced 2025-12-15 07:43:50 +00:00

Updated so if getParameter() is already defined, it will ignore redefinition

This commit is contained in:
Bryan Roe
2022-06-08 20:37:42 -07:00
parent 9021b2a791
commit bdc1fc4d1b
2 changed files with 72 additions and 53 deletions

File diff suppressed because one or more lines are too long

View File

@@ -15,66 +15,85 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
try
Object.defineProperty(Array.prototype, 'getParameterEx', {
{ Object.defineProperty(Array.prototype, 'getParameterEx',
value: function (name, defaultValue)
{ {
var i, ret; value: function (name, defaultValue)
for (i = 0; i < this.length; ++i)
{ {
if (this[i].startsWith(name + '=')) var i, ret;
for (i = 0; i < this.length; ++i)
{ {
ret = this[i].substring(name.length + 1); if (this[i].startsWith(name + '='))
if (ret.startsWith('"')) { ret = ret.substring(1, ret.length - 1); } {
return (ret); ret = this[i].substring(name.length + 1);
if (ret.startsWith('"')) { ret = ret.substring(1, ret.length - 1); }
return (ret);
}
}
return (defaultValue);
}
});
Object.defineProperty(Array.prototype, 'getParameter',
{
value: function (name, defaultValue)
{
return (this.getParameterEx('--' + name, defaultValue));
}
});
}
catch(x)
{ }
try
{
Object.defineProperty(Array.prototype, 'getParameterIndex',
{
value: function (name)
{
var i;
for (i = 0; i < this.length; ++i)
{
if (this[i].startsWith('--' + name + '='))
{
return (i);
}
}
return (-1);
}
});
}
catch(x)
{ }
try
{
Object.defineProperty(Array.prototype, 'deleteParameter',
{
value: function (name)
{
var i = this.getParameterIndex(name);
if(i>=0)
{
this.splice(i, 1);
} }
} }
return (defaultValue); });
} }
}); catch(x)
Object.defineProperty(Array.prototype, 'getParameter', { }
{ try
value: function (name, defaultValue) {
Object.defineProperty(Array.prototype, 'getParameterValue',
{ {
return (this.getParameterEx('--' + name, defaultValue)); value: function (i)
}
});
Object.defineProperty(Array.prototype, 'getParameterIndex',
{
value: function (name)
{
var i;
for (i = 0; i < this.length; ++i)
{ {
if (this[i].startsWith('--' + name + '=')) var ret = this[i].substring(this[i].indexOf('=')+1);
{ if (ret.startsWith('"')) { ret = ret.substring(1, ret.length - 1); }
return (i); return (ret);
}
} }
return (-1); });
} }
}); catch(x)
Object.defineProperty(Array.prototype, 'deleteParameter', { }
{
value: function (name)
{
var i = this.getParameterIndex(name);
if(i>=0)
{
this.splice(i, 1);
}
}
});
Object.defineProperty(Array.prototype, 'getParameterValue',
{
value: function (i)
{
var ret = this[i].substring(this[i].indexOf('=')+1);
if (ret.startsWith('"')) { ret = ret.substring(1, ret.length - 1); }
return (ret);
}
});
function checkParameters(parms) function checkParameters(parms)
{ {