本文整理汇总了C++中CCodeChain::EvaluateArgs方法的典型用法代码示例。如果您正苦于以下问题:C++ CCodeChain::EvaluateArgs方法的具体用法?C++ CCodeChain::EvaluateArgs怎么用?C++ CCodeChain::EvaluateArgs使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CCodeChain
的用法示例。
在下文中一共展示了CCodeChain::EvaluateArgs方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CONSTLIT
ICCItem *fnSubst (CEvalContext *pCtx, ICCItem *pArguments, DWORD dwData)
// fnSubst
//
// Substitutes string parameters
//
// (subst string arg1 arg2 ... argn)
{
CCodeChain *pCC = pCtx->pCC;
ICCItem *pArgs;
// Evaluate the arguments and validate them
pArgs = pCC->EvaluateArgs(pCtx, pArguments, CONSTLIT("s*"));
if (pArgs->IsError())
return pArgs;
CString sPattern = pArgs->GetElement(0)->GetStringValue();
// Do the substitution
char szResult[4096];
char *pPos = sPattern.GetASCIIZPointer();
char *pDest = szResult;
char *pEndDest = szResult + sizeof(szResult) - 1;
while (*pPos != '\0' && pDest < pEndDest)
{
if (*pPos == '%')
{
pPos++;
int iArg = strParseInt(pPos, 0, &pPos, NULL);
if (iArg > 0)
{
CString sParam = pArgs->GetElement(iArg)->GetStringValue();
char *pParam = sParam.GetASCIIZPointer();
while (*pParam != '\0' && pDest < pEndDest)
*pDest++ = *pParam++;
pPos++;
}
else
{
if (*pPos == '%')
*pDest++ = *pPos++;
}
}
else
*pDest++ = *pPos++;
}
// Done
*pDest = '\0';
pArgs->Discard(pCC);
return pCC->CreateString(CString(szResult));
}
示例2: if
ICCItem *fnRandom (CEvalContext *pCtx, ICCItem *pArguments, DWORD dwData)
// fnRandom
//
// (random from to) -> number
// (random list) -> random item in list
{
CCodeChain *pCC = pCtx->pCC;
ICCItem *pArgs;
ICCItem *pResult;
// Evaluate the arguments and validate them
pArgs = pCC->EvaluateArgs(pCtx, pArguments, CONSTLIT("*"));
if (pArgs->IsError())
return pArgs;
// Do stuff based on parameters
if (pArgs->GetCount() == 2)
{
int iOp1 = pArgs->GetElement(0)->GetIntegerValue();
int iOp2 = pArgs->GetElement(1)->GetIntegerValue();
pArgs->Discard(pCC);
pResult = pCC->CreateInteger(mathRandom(iOp1, iOp2));
}
else if (pArgs->GetCount() == 1)
{
ICCItem *pList = pArgs->GetElement(0);
if (pList->IsNil())
pResult = pCC->CreateNil();
else if (pList->GetCount() == 0)
pResult = pCC->CreateNil();
else
pResult = pList->GetElement(mathRandom(0, pList->GetCount()-1))->Reference();
pArgs->Discard(pCC);
}
else
{
pResult = pCC->CreateNil();
pArgs->Discard(pCC);
}
// Done
return pResult;
}