本文整理汇总了C++中CFunctionsScopePtr类的典型用法代码示例。如果您正苦于以下问题:C++ CFunctionsScopePtr类的具体用法?C++ CFunctionsScopePtr怎么用?C++ CFunctionsScopePtr使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CFunctionsScopePtr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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));
}
示例2: 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)");
}
示例3: 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);
}
}
}
}
}
示例4: 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));
}
示例5: 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();
}
示例6: scCharToInt
static void scCharToInt(const CFunctionsScopePtr &c, void *) {
string str = c->getArgument("ch")->toString();;
int val = 0;
if (str.length()>0)
val = (int)str.c_str()[0];
c->setReturnVar(c->newScriptVar(val));
}
示例7: 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));
}
示例8: scTrace
static void scTrace(const CFunctionsScopePtr &c, void * userdata) {
CTinyJS *js = (CTinyJS*)userdata;
if(c->getArgumentsLength())
c->getArgument(0)->trace();
else
js->getRoot()->trace("root");
}
示例9: 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));
}
示例10: scStringConcat
static void scStringConcat(const CFunctionsScopePtr &c, void *userdata) {
int length = c->getArgumentsLength();
string str = this2string(c);
for(int32_t i=ptr2int32(userdata); i<length; i++)
str.append(c->getArgument(i)->toString());
c->setReturnVar(c->newScriptVar(str));
}
示例11: scStringCharCodeAt
static void scStringCharCodeAt(const CFunctionsScopePtr &c, void *) {
string str = this2string(c);
int p = c->getArgument("pos")->toNumber().toInt32();
if (p>=0 && p<(int)str.length())
c->setReturnVar(c->newScriptVar((unsigned char)str.at(p)));
else
c->setReturnVar(c->constScriptVar(NaN));
}
示例12: scStringCharAt
static void scStringCharAt(const CFunctionsScopePtr &c, void *) {
string str = this2string(c);
int p = c->getArgument("pos")->toNumber().toInt32();
if (p>=0 && p<(int)str.length())
c->setReturnVar(c->newScriptVar(str.substr(p, 1)));
else
c->setReturnVar(c->newScriptVar(""));
}
示例13: scStringLocaleCompare
static void scStringLocaleCompare(const CFunctionsScopePtr &c, void *userdata) {
string str = this2string(c);
string compareString = c->getArgument("compareString")->toString();
int32_t val = 0;
if(str<compareString) val = -1;
else if(str>compareString) val = 1;
c->setReturnVar(c->newScriptVar(val));
}
示例14: scStringReplace
static void scStringReplace(const CFunctionsScopePtr &c, void *) {
const string str = this2string(c);
CScriptVarPtr newsubstrVar = c->getArgument("newsubstr");
string substr, ret_str;
bool global, ignoreCase, sticky;
bool isRegExp = getRegExpData(c, "substr", false, "flags", substr, global, ignoreCase, sticky);
if(isRegExp && !newsubstrVar->isFunction()) {
#ifndef NO_REGEXP
regex::flag_type flags = regex_constants::ECMAScript;
if(ignoreCase) flags |= regex_constants::icase;
regex_constants::match_flag_type mflags = regex_constants::match_default;
if(!global) mflags |= regex_constants::format_first_only;
if(sticky) mflags |= regex_constants::match_continuous;
ret_str = regex_replace(str, regex(substr, flags), newsubstrVar->toString(), mflags);
#endif /* NO_REGEXP */
} else {
bool (*search)(const string &, const string::const_iterator &, const string &, bool, bool, string::const_iterator &, string::const_iterator &);
#ifndef NO_REGEXP
if(isRegExp)
search = regex_search;
else
#endif /* NO_REGEXP */
search = string_search;
string newsubstr;
vector<CScriptVarPtr> arguments;
if(!newsubstrVar->isFunction())
newsubstr = newsubstrVar->toString();
global = global && substr.length();
string::const_iterator search_begin=str.begin(), match_begin, match_end;
if(search(str, search_begin, substr, ignoreCase, sticky, match_begin, match_end)) {
do {
ret_str.append(search_begin, match_begin);
if(newsubstrVar->isFunction()) {
arguments.push_back(c->newScriptVar(string(match_begin, match_end)));
newsubstr = c->getContext()->callFunction(newsubstrVar, arguments)->toString();
arguments.pop_back();
}
ret_str.append(newsubstr);
#if 1 /* Fix from "vcmpeq" (see Issue 14) currently untested */
if (match_begin == match_end) {
if (search_begin != str.end())
++search_begin;
else
break;
} else {
search_begin = match_end;
}
#else
search_begin = match_end;
#endif
} while(global && search(str, search_begin, substr, ignoreCase, sticky, match_begin, match_end));
}
ret_str.append(search_begin, str.end());
}
c->setReturnVar(c->newScriptVar(ret_str));
}
示例15: 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)));
}