本文整理汇总了C++中CCodeChain类的典型用法代码示例。如果您正苦于以下问题:C++ CCodeChain类的具体用法?C++ CCodeChain怎么用?C++ CCodeChain使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CCodeChain类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
ICCItem *fnMath (CEvalContext *pCtx, ICCItem *pArgs, DWORD dwData)
// fnMath
//
// Simple integer arithmetic
//
// (sqrt int1)
{
CCodeChain *pCC = pCtx->pCC;
// Compute
switch (dwData)
{
case FN_MATH_SQRT:
{
int iValue = pArgs->GetElement(0)->GetIntegerValue();
if (iValue >= 0)
return pCC->CreateInteger(mathSqrt(iValue));
else
return pCC->CreateError(CONSTLIT("Imaginary number"), pArgs->GetElement(0));
}
default:
ASSERT(false);
return pCC->CreateNil();
}
}
示例2: DefineGlobalWeaponType
void DefineGlobalWeaponType (CCodeChain &CC, const CString &sVar, CItemType *pWeaponType)
{
if (pWeaponType)
CC.DefineGlobalInteger(sVar, pWeaponType->GetUNID());
else
CC.DefineGlobal(sVar, CC.CreateNil());
}
示例3: CONSTLIT
ICCItem *fnAtmCreate (CEvalContext *pCtx, ICCItem *pArguments, DWORD dwData)
// fnAtmCreate
//
// Creates a new atom table
//
// (atmAtomTable ((atom1 entry1) (atom2 entry2) ... (atomn entryn))) -> atmtable
{
CCodeChain *pCC = pCtx->pCC;
ICCItem *pArgs;
ICCItem *pAtomTable;
ICCItem *pList;
int i;
// Evaluate the argument
pArgs = pCC->EvaluateArgs(pCtx, pArguments, CONSTLIT("l"));
if (pArgs->IsError())
return pArgs;
// Create the table
pAtomTable = pCC->CreateAtomTable();
if (pAtomTable->IsError())
return pAtomTable;
// Add each entry
pList = pArgs->Head(pCC);
for (i = 0; i < pList->GetCount(); i++)
{
ICCItem *pPair = pList->GetElement(i);
ICCItem *pResult;
// Make sure we have two elements
if (pPair->GetCount() != 2)
{
pAtomTable->Discard(pCC);
return pCC->CreateError(CONSTLIT("Invalid format for atom table entry:"), pPair);
}
// Get the atom and the entry
pResult = pAtomTable->AddEntry(pCC, pPair->GetElement(0), pPair->GetElement(1));
if (pResult->IsError())
{
pAtomTable->Discard(pCC);
return pResult;
}
pResult->Discard(pCC);
}
// Done
pArgs->Discard(pCC);
return pAtomTable;
}
示例4: SetStringValue
void CCSymbolTable::SetStringValue (CCodeChain &CC, const CString &sKey, const CString &sValue)
// SetStringValue
//
// Sets a string value
{
ICCItem *pKey = CC.CreateString(sKey);
ICCItem *pValue = CC.CreateString(sValue);
AddEntry(&CC, pKey, pValue);
pKey->Discard(&CC);
pValue->Discard(&CC);
}
示例5: SetIntegerValue
void CCSymbolTable::SetIntegerValue (CCodeChain &CC, const CString &sKey, int iValue)
// SetIntegerValue
//
// Sets an integer value
{
ICCItem *pKey = CC.CreateString(sKey);
ICCItem *pValue = CC.CreateInteger(iValue);
AddEntry(&CC, pKey, pValue);
pKey->Discard(&CC);
pValue->Discard(&CC);
}
示例6: strFind
ICCItem *fnStrFind (CEvalContext *pCtx, ICCItem *pArgs, DWORD dwData)
// fnStrFind
//
// Finds a string in some text
{
CCodeChain *pCC = pCtx->pCC;
int iPos = strFind(pArgs->GetElement(0)->GetStringValue(), pArgs->GetElement(1)->GetStringValue());
if (iPos == -1)
return pCC->CreateNil();
else
return pCC->CreateInteger(iPos);
}
示例7: DefineGlobalSpaceObject
void DefineGlobalSpaceObject (CCodeChain &CC, const CString &sVar, CSpaceObject *pObj)
// DefineGlobalSpaceObject
//
// Defines a global variable and assigns it the given space object. If pObj
// is NULL then the variable is Nil.
{
if (pObj)
CC.DefineGlobalInteger(sVar, (int)pObj);
else
{
ICCItem *pValue = CC.CreateNil();
CC.DefineGlobal(sVar, pValue);
pValue->Discard(&CC);
}
}
示例8: DefineGlobalItem
void DefineGlobalItem (CCodeChain &CC, const CString &sVar, const CItem &Item)
// DefineGlobalItem
//
// Defines a global variable and assigns it the given item
{
ICCItem *pItem = CreateListFromItem(CC, Item);
CC.DefineGlobal(sVar, pItem);
pItem->Discard(&CC);
}
示例9: DefineGlobalVector
void DefineGlobalVector (CCodeChain &CC, const CString &sVar, const CVector &vVector)
// DefineGlobalVector
//
// Defines a global variable and assigns it the given vector
{
ICCItem *pValue = CreateListFromVector(CC, vVector);
CC.DefineGlobal(sVar, pValue);
pValue->Discard(&CC);
}
示例10: pageLibraryInit
ALERROR pageLibraryInit (CCodeChain &CC)
{
ALERROR error;
int i;
for (i = 0; i < EXTENSIONS_COUNT; i++)
if (error = CC.RegisterPrimitive(&g_Extensions[i]))
return error;
return NOERROR;
}
示例11: if
ICCItem *fnSeededRandom (CEvalContext *pCtx, ICCItem *pArgs, DWORD dwData)
// fnSeededRandom
//
// (seededRandom seed from to) -> number
// (seededRandom seed list) -> random item in list
{
CCodeChain *pCC = pCtx->pCC;
ICCItem *pResult;
int iSeed = pArgs->GetElement(0)->GetIntegerValue();
// Do stuff based on parameters
if (pArgs->GetCount() == 3)
{
int iOp1 = pArgs->GetElement(1)->GetIntegerValue();
int iOp2 = pArgs->GetElement(2)->GetIntegerValue();
pResult = pCC->CreateInteger(mathSeededRandom(iSeed, iOp1, iOp2));
}
else if (pArgs->GetCount() == 2)
{
ICCItem *pList = pArgs->GetElement(1);
if (pList->IsNil())
pResult = pCC->CreateNil();
else if (pList->GetCount() == 0)
pResult = pCC->CreateNil();
else
pResult = pList->GetElement(mathSeededRandom(iSeed, 0, pList->GetCount()-1))->Reference();
}
else
pResult = pCC->CreateNil();
// Done
return pResult;
}
示例12: CreateDataFromItem
CString CreateDataFromItem (CCodeChain &CC, ICCItem *pItem)
// CreateDataFromItem
//
// Encodes the item in a string suitable for storage.
// (Use Link to reverse).
{
// Set quoted before we unlink
// Note: This might be a hack...it probably makes more sense to mark
// all function return values as 'quoted'
bool bOldQuoted = (pItem->IsQuoted() ? true : false);
pItem->SetQuoted();
CString sData = CC.Unlink(pItem);
if (!bOldQuoted)
pItem->ClearQuoted();
return sData;
}