Added support for JS getIntValue() min/max/clamp parameters.
git-svn-id: http://voip.null.ro/svn/yate@6023 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
parent
ca9e87c0ba
commit
093e51fc39
|
@ -1545,21 +1545,21 @@ void ExpEvaluator::dump(String& res, bool lineNo) const
|
|||
return dump(m_opcodes,res,lineNo);
|
||||
}
|
||||
|
||||
int64_t ExpOperation::valInteger() const
|
||||
int64_t ExpOperation::valInteger(int64_t defVal) const
|
||||
{
|
||||
return isInteger() ? number() : 0;
|
||||
return isInteger() ? number() : defVal;
|
||||
}
|
||||
|
||||
int64_t ExpOperation::toNumber() const
|
||||
int64_t ExpOperation::toNumber() const
|
||||
{
|
||||
if (isInteger())
|
||||
return number();
|
||||
return toInt64(nonInteger());
|
||||
}
|
||||
|
||||
bool ExpOperation::valBoolean() const
|
||||
bool ExpOperation::valBoolean(bool defVal) const
|
||||
{
|
||||
return isInteger() ? (number() != 0) : !null();
|
||||
return isInteger() ? (number() != 0) : (defVal || !null());
|
||||
}
|
||||
|
||||
const char* ExpOperation::typeOf() const
|
||||
|
@ -1628,10 +1628,10 @@ const char* ExpWrapper::typeOf() const
|
|||
}
|
||||
}
|
||||
|
||||
bool ExpWrapper::valBoolean() const
|
||||
bool ExpWrapper::valBoolean(bool defVal) const
|
||||
{
|
||||
if (!m_object)
|
||||
return false;
|
||||
return defVal;
|
||||
return !JsParser::isNull(*this);
|
||||
}
|
||||
|
||||
|
|
|
@ -1141,9 +1141,10 @@ public:
|
|||
|
||||
/**
|
||||
* Retrieve the numeric value of the operation
|
||||
* @return Number contained in operation, zero if not a number
|
||||
* @param defVal Default to return if not a number
|
||||
* @return Number contained in operation
|
||||
*/
|
||||
virtual int64_t valInteger() const;
|
||||
virtual int64_t valInteger(int64_t defVal = 0) const;
|
||||
|
||||
/**
|
||||
* Convert to number
|
||||
|
@ -1153,9 +1154,10 @@ public:
|
|||
|
||||
/**
|
||||
* Retrieve the boolean value of the operation
|
||||
* @param defVal Default to return if not a boolean
|
||||
* @return True if the operation is to be interpreted as true value
|
||||
*/
|
||||
virtual bool valBoolean() const;
|
||||
virtual bool valBoolean(bool defVal = false) const;
|
||||
|
||||
/**
|
||||
* Retrieve the name of the type of the value of this operation
|
||||
|
@ -1214,9 +1216,10 @@ public:
|
|||
|
||||
/**
|
||||
* Retrieve the boolean value of the function (not of its result)
|
||||
* @param defVal Parameter ignored
|
||||
* @return Always true
|
||||
*/
|
||||
virtual bool valBoolean() const
|
||||
virtual bool valBoolean(bool defVal = false) const
|
||||
{ return true; }
|
||||
|
||||
/**
|
||||
|
@ -1271,9 +1274,10 @@ public:
|
|||
|
||||
/**
|
||||
* Retrieve the boolean value of the operation
|
||||
* @param defVal Parameter ignored
|
||||
* @return True if the wrapped object is to be interpreted as true value
|
||||
*/
|
||||
virtual bool valBoolean() const;
|
||||
virtual bool valBoolean(bool defVal = false) const;
|
||||
|
||||
/**
|
||||
* Retrieve the name of the type of the value of this operation
|
||||
|
|
|
@ -2388,7 +2388,19 @@ bool JsConfigFile::runNative(ObjList& stack, const ExpOperation& oper, GenObject
|
|||
}
|
||||
else if (oper.name() == YSTRING("getIntValue")) {
|
||||
int64_t defVal = 0;
|
||||
int64_t minVal = LLONG_MIN;
|
||||
int64_t maxVal = LLONG_MAX;
|
||||
bool clamp = true;
|
||||
switch (extractArgs(stack,oper,context,args)) {
|
||||
case 6:
|
||||
clamp = static_cast<ExpOperation*>(args[5])->valBoolean(clamp);
|
||||
// fall through
|
||||
case 5:
|
||||
maxVal = static_cast<ExpOperation*>(args[4])->valInteger(maxVal);
|
||||
// fall through
|
||||
case 4:
|
||||
minVal = static_cast<ExpOperation*>(args[3])->valInteger(minVal);
|
||||
// fall through
|
||||
case 3:
|
||||
defVal = static_cast<ExpOperation*>(args[2])->valInteger();
|
||||
// fall through
|
||||
|
@ -2399,7 +2411,7 @@ bool JsConfigFile::runNative(ObjList& stack, const ExpOperation& oper, GenObject
|
|||
}
|
||||
const String& sect = *static_cast<ExpOperation*>(args[0]);
|
||||
const String& name = *static_cast<ExpOperation*>(args[1]);
|
||||
ExpEvaluator::pushOne(stack,new ExpOperation(m_config.getInt64Value(sect,name,defVal),name));
|
||||
ExpEvaluator::pushOne(stack,new ExpOperation(m_config.getInt64Value(sect,name,defVal,minVal,maxVal,clamp),name));
|
||||
}
|
||||
else if (oper.name() == YSTRING("getBoolValue")) {
|
||||
bool defVal = false;
|
||||
|
@ -2534,7 +2546,19 @@ bool JsConfigSection::runNative(ObjList& stack, const ExpOperation& oper, GenObj
|
|||
}
|
||||
else if (oper.name() == YSTRING("getIntValue")) {
|
||||
int64_t val = 0;
|
||||
int64_t minVal = LLONG_MIN;
|
||||
int64_t maxVal = LLONG_MAX;
|
||||
bool clamp = true;
|
||||
switch (extractArgs(stack,oper,context,args)) {
|
||||
case 5:
|
||||
clamp = static_cast<ExpOperation*>(args[4])->valBoolean(clamp);
|
||||
// fall through
|
||||
case 4:
|
||||
maxVal = static_cast<ExpOperation*>(args[3])->valInteger(maxVal);
|
||||
// fall through
|
||||
case 3:
|
||||
minVal = static_cast<ExpOperation*>(args[2])->valInteger(minVal);
|
||||
// fall through
|
||||
case 2:
|
||||
val = static_cast<ExpOperation*>(args[1])->valInteger();
|
||||
// fall through
|
||||
|
@ -2546,7 +2570,11 @@ bool JsConfigSection::runNative(ObjList& stack, const ExpOperation& oper, GenObj
|
|||
const String& name = *static_cast<ExpOperation*>(args[0]);
|
||||
NamedList* sect = m_owner->config().getSection(toString());
|
||||
if (sect)
|
||||
val = sect->getInt64Value(name,val);
|
||||
val = sect->getInt64Value(name,val,minVal,maxVal,clamp);
|
||||
else if (val < minVal)
|
||||
val = minVal;
|
||||
else if (val > maxVal)
|
||||
val = maxVal;
|
||||
ExpEvaluator::pushOne(stack,new ExpOperation(val,name));
|
||||
}
|
||||
else if (oper.name() == YSTRING("getBoolValue")) {
|
||||
|
|
Loading…
Reference in New Issue