本文整理汇总了C++中CFunctionsScopePtr::getArgument方法的典型用法代码示例。如果您正苦于以下问题:C++ CFunctionsScopePtr::getArgument方法的具体用法?C++ CFunctionsScopePtr::getArgument怎么用?C++ CFunctionsScopePtr::getArgument使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CFunctionsScopePtr
的用法示例。
在下文中一共展示了CFunctionsScopePtr::getArgument方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: scRegExpExec
static void scRegExpExec(const CFunctionsScopePtr &c, void *) {
CScriptVarRegExpPtr This = c->getArgument("this");
if(This)
c->setReturnVar(This->exec(c->getArgument("str")->toString()));
else
c->throwError(TypeError, "Object is not a RegExp-Object in exec(str)");
}
示例2: scStringSplit
static void scStringSplit(const CFunctionsScopePtr &c, void *) {
string str = c->getArgument("this")->getString();
CScriptVarPtr sep_var = c->getArgument("separator");
CScriptVarPtr limit_var = c->getArgument("limit");
int limit = limit_var->isUndefined() ? 0x7fffffff : limit_var->getInt();
CScriptVarPtr result(newScriptVar(c->getContext(), Array));
c->setReturnVar(result);
if(limit == 0 || !str.size())
return;
else if(sep_var->isUndefined()) {
result->setArrayIndex(0, c->newScriptVar(str));
return;
}
string sep = sep_var->getString();
if(sep.size() == 0) {
for(int i=0; i<min((int)sep.size(), limit); ++i)
result->setArrayIndex(i, c->newScriptVar(str.substr(i,1)));
return;
}
int length = 0;
string::size_type pos = 0, last_pos=0;
do {
pos = str.find(sep, last_pos);
result->setArrayIndex(length++, c->newScriptVar(str.substr(last_pos ,pos-last_pos)));
if(length == limit || pos == string::npos) break;
last_pos = pos+sep.size();
} while (last_pos < str.size());
}
示例3: scStringConcat
static void scStringConcat(const CFunctionsScopePtr &c, void *userdata) {
int length = c->getArgumentsLength();
string str = c->getArgument("this")->getString();
for(int i=(int)userdata; i<length; i++)
str.append(c->getArgument(i)->getString());
c->setReturnVar(c->newScriptVar(str));
}
示例4: scStringIndexOf
static void scStringIndexOf(const CFunctionsScopePtr &c, void *userdata) {
string str = c->getArgument("this")->getString();
string search = c->getArgument("search")->getString();
size_t p = (userdata==0) ? str.find(search) : str.rfind(search);
int val = (p==string::npos) ? -1 : p;
c->setReturnVar(c->newScriptVar(val));
}
示例5: scArrayPush
static void scArrayPush(const CFunctionsScopePtr &c, void *data) {
CScriptVarPtr arr = c->getArgument("this");
int l = arr->getArrayLength();
int args = c->getArgumentsLength();
for (int i=0;i<args;i++)
arr->setArrayIndex(l+i, c->getArgument(i));
}
示例6: scArraySort
static void scArraySort(const CFunctionsScopePtr &c, void *data) {
CScriptVarPtr arr = c->getArgument("this");
CScriptVarFunctionPtr cmp_fnc;
uint32_t len = arr->getLength();
if(len > 1) {
int args = c->getArgumentsLength();
if(args) {
cmp_fnc = c->getArgument(0);
if(!cmp_fnc) c->throwError(TypeError, "invalid Array.prototype.sort argument");
}
SCRIPTVAR_CHILDS_it begin = lower_bound(arr->Childs.begin(), arr->Childs.end(), "0");
/* in ECMAScript the sort algorithm is not specified
* in some cases sort throws a TypeError e.G. an array element is read-only, non-configurable, getter or setter
* this will result in a partially sorted array
* in worst case the sort algorithm results in an endless loop (more getters with constant return value)
*
* 42TinyJS checks before sort if an element read-only, setter or getter and throws immediately a TypeError
*/
for(SCRIPTVAR_CHILDS_it it = begin; it != arr->Childs.end(); ++it) {
if(!(*it)->isWritable()) c->throwError(TypeError, "property "+(*it)->getName()+" is read-only");
if(!(*it)->isConfigurable()) c->throwError(TypeError, "property "+(*it)->getName()+" is non-configurable");
if(!(*it)->getVarPtr()->isAccessor()) c->throwError(TypeError, "property "+(*it)->getName()+" is a getter and/or a setter");
}
sort(begin, arr->Childs.end(), ::cmp_fnc(c, cmp_fnc));
uint32_t idx = 0;
for(SCRIPTVAR_CHILDS_it it=begin; it != arr->Childs.end(); ++it, ++idx)
(*it)->reName(int2string(idx));
sort(begin, arr->Childs.end(), cmp_by_name);
}
c->setReturnVar(arr);
}
示例7: scArrayPush
static void scArrayPush(const CFunctionsScopePtr &c, void *data) {
CScriptVarPtr arr = c->getArgument("this");
uint32_t len = c->getLength(arr);
uint32_t args = c->getArgumentsLength();
for (uint32_t i=0; i<args; ++i)
c->setProperty(arr, i, c->getArgument(i));
}
示例8: getRegExpData
//************************************
// Method: getRegExpData
// FullName: getRegExpData
// Access: public static
// Returns: bool true if regexp-param=RegExp-Object / other false
// Qualifier:
// Parameter: const CFunctionsScopePtr & c
// Parameter: const string & regexp - parameter name of the regexp
// Parameter: bool noUndefined - true an undefined regexp aims in "" else in "undefined"
// Parameter: const string & flags - parameter name of the flags
// Parameter: string & substr - rgexp.source
// Parameter: bool & global
// Parameter: bool & ignoreCase
// Parameter: bool & sticky
//************************************
static CScriptVarPtr getRegExpData(const CFunctionsScopePtr &c, const string ®exp, bool noUndefined, const char *flags_argument, string &substr, bool &global, bool &ignoreCase, bool &sticky) {
CScriptVarPtr regexpVar = c->getArgument(regexp);
if(regexpVar->isRegExp()) {
#ifndef NO_REGEXP
CScriptVarRegExpPtr RegExp(regexpVar);
substr = RegExp->Regexp();
ignoreCase = RegExp->IgnoreCase();
global = RegExp->Global();
sticky = RegExp->Sticky();
return RegExp;
#endif /* NO_REGEXP */
} else {
substr.clear();
if(!noUndefined || !regexpVar->isUndefined()) substr = regexpVar->toString();
CScriptVarPtr flagVar;
if(flags_argument && (flagVar = c->getArgument(flags_argument)) && !flagVar->isUndefined()) {
string flags = flagVar->toString();
string::size_type pos = flags.find_first_not_of("gimy");
if(pos != string::npos) {
c->throwError(SyntaxError, string("invalid regular expression flag ")+flags[pos]);
}
global = flags.find_first_of('g')!=string::npos;
ignoreCase = flags.find_first_of('i')!=string::npos;
sticky = flags.find_first_of('y')!=string::npos;
} else
global = ignoreCase = sticky = false;
}
return CScriptVarPtr();
}
示例9: scArrayRemove
static void scArrayRemove(const CFunctionsScopePtr &c, void *data) {
CScriptVarPtr obj = c->getArgument("obj");
CScriptVarPtr arr = c->getArgument("this");
int i;
vector<int> removedIndices;
int l = arr->getArrayLength();
CScriptVarPtr equal = c->constScriptVar(Undefined);
for (i=0;i<l;i++) {
equal = obj->mathsOp(arr->getArrayIndex(i), LEX_EQUAL);
if(equal->toBoolean()) {
removedIndices.push_back(i);
}
}
if(removedIndices.size()) {
vector<int>::iterator remove_it = removedIndices.begin();
int next_remove = *remove_it;
int next_insert = *remove_it++;
for (i=next_remove;i<l;i++) {
CScriptVarLinkPtr link = arr->findChild(int2string(i));
if(i == next_remove) {
if(link) arr->removeLink(link);
if(remove_it != removedIndices.end())
next_remove = *remove_it++;
} else {
if(link) {
arr->setArrayIndex(next_insert++, link);
arr->removeLink(link);
}
}
}
}
}
示例10: scStringCharCodeAt
static void scStringCharCodeAt(const CFunctionsScopePtr &c, void *) {
string str = c->getArgument("this")->getString();
int p = c->getArgument("pos")->getInt();
if (p>=0 && p<(int)str.length())
c->setReturnVar(c->newScriptVar(str.at(p)));
else
c->setReturnVar(c->newScriptVar(0));
}
示例11: scStringSubstr
static void scStringSubstr(const CFunctionsScopePtr &c, void *userdata) {
string str = this2string(c);
int32_t length = c->getArgumentsLength()-ptr2int32(userdata);
int32_t start = c->getArgument("start")->toNumber().toInt32();
if(start<0 || start>=(int)str.size())
c->setReturnVar(c->newScriptVar(""));
else if(length>1) {
int length = c->getArgument("length")->toNumber().toInt32();
c->setReturnVar(c->newScriptVar(str.substr(start, length)));
} else
c->setReturnVar(c->newScriptVar(str.substr(start)));
}
示例12: scStringSubstr
static void scStringSubstr(const CFunctionsScopePtr &c, void *userdata) {
string str = c->getArgument("this")->getString();
int length = c->getArgumentsLength()-(int)userdata;
int start = c->getArgument("start")->getInt();
if(start<0 || start>=(int)str.size())
c->setReturnVar(c->newScriptVar(""));
else if(length>1) {
int length = c->getArgument("length")->getInt();
c->setReturnVar(c->newScriptVar(str.substr(start, length)));
} else
c->setReturnVar(c->newScriptVar(str.substr(start)));
}
示例13: scArrayJoin
static void scArrayJoin(const CFunctionsScopePtr &c, void *data) {
string sep = c->getArgument("separator")->toString();
CScriptVarPtr arr = c->getArgument("this");
ostringstream sstr;
int l = arr->getArrayLength();
for (int i=0;i<l;i++) {
if (i>0) sstr << sep;
sstr << arr->getArrayIndex(i)->toString();
}
c->setReturnVar(c->newScriptVar(sstr.str()));
}
示例14: scArrayRemove
static void scArrayRemove(const CFunctionsScopePtr &c, void *data) {
CScriptVarPtr obj = c->getArgument("obj");
CScriptVarPtr arr = c->getArgument("this");
uint32_t l = arr->getLength();
uint32_t offset = 0;
for(SCRIPTVAR_CHILDS_it it= lower_bound(arr->Childs.begin(), arr->Childs.end(), "0"); it != arr->Childs.end(); ++it) {
while(it != arr->Childs.end() && obj->mathsOp(it->getter(), LEX_EQUAL)->toBoolean()) {
it = arr->Childs.erase(it);
offset++;
}
if(offset && it != arr->Childs.end())
(*it)->reName(int2string((uint32_t)strtoul((*it)->getName().c_str(), 0, 10)-offset) );
}
}
示例15: scArrayFill
static void scArrayFill(const CFunctionsScopePtr &c, void *data) {
CScriptVarPtr arr = c->getArgument("this");
uint32_t len = c->getLength(arr);
CNumber startNumber=0, endNumber=len;
CScriptVarPtr value = c->getArgument(0);
CScriptVarPtr startVar = c->getArgument(1);
CScriptVarPtr endVar = c->getArgument(2);
c->setReturnVar(arr);
if(!startVar->isUndefined()) startNumber = startVar->toNumber();
if(!endVar->isUndefined()) endNumber = endVar->toNumber();
uint32_t start = (startNumber.sign()<0 ? startNumber+len : startNumber).clamp(0, len).toUInt32();
uint32_t end = (endNumber.sign()<0 ? endNumber+len : endNumber).clamp(0, len).toUInt32();
for(; start < end; ++start) c->setProperty(arr, start, value);
}