本文整理汇总了C++中VariableList::AddVar方法的典型用法代码示例。如果您正苦于以下问题:C++ VariableList::AddVar方法的具体用法?C++ VariableList::AddVar怎么用?C++ VariableList::AddVar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类VariableList
的用法示例。
在下文中一共展示了VariableList::AddVar方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Execute
//执行
void COpScript::Execute(CMoveShape* pShape)
{
#ifdef _RUNSTACKINFO1_
CMessage::AsyWriteFile(GetGame()->GetStatckFileName(), "COpScript::Execute() begin");
#endif
// [5/4/2009 chenxianj]
//CScript *pTempScript = PopFreeScript("COpScript::Execute");
//if (pTempScript)
//{
// pTempScript->SetVariableList(m_pParam->pVariableList);
// pTempScript->SetUsedItemID(m_pParam->GoodsGuid);
// pTempScript->SetSrcShapeEx(m_pParam->pUser);
// // [5/4/2009 chenxianj]
// itExpress it = m_Expressions.begin();
// for(;it != m_Expressions.end();it++)
// {
// if(m_pParam->pUser)
// pTempScript->SetRegion(dynamic_cast<CRegion*>(m_pParam->pUser->GetFather()));
// else
// pTempScript->SetRegion(NULL);
// (*it)->Execute(pTempScript,pShape);
// }
// // [5/4/2009 chenxianj]
// PushFreeScript(pTempScript);
//}
Script::RunEnv env( m_pParam->pUser, pShape, static_cast<CRegion*>( m_pParam->pUser->GetFather() ),
m_pParam->pVariableList );
VariableList *varList = m_pParam->pVariableList;
if( !varList->AddVar( "$ParamA", (double)(DWORD)m_pParam->pUser ) )
{
varList->SetVarValue( "$ParamA", (double)(DWORD) m_pParam->pUser );
}
if( !varList->AddVar( "$ParamB", (double)(DWORD)pShape ) )
{
varList->SetVarValue( "$ParamB", (double)(DWORD) pShape );
}
Script *script = GetInst( ScriptSys ).NewScript( env );
for( itExpress it = m_Expressions.begin(); it != m_Expressions.end(); ++ it )
{
CExpressions *exp = *it;
int ret = exp->Execute( script, pShape );
if( !script->CanDelete( ret ) )
{
// yield script, cannot run.
assert( "Yield script" && 0 );
}
}
GetInst( ScriptSys ).DelScript( script );
#ifdef _RUNSTACKINFO1_
CMessage::AsyWriteFile(GetGame()->GetStatckFileName(), "COpScript::Execute() end");
#endif
}
示例2: AddVar
///
/// 添加一个脚本变量到指定变量列表里
///
/// ret = AddVar( operType, "$varName", initVal, count =1 )
/// @param operType: VT_SCRIPT, VT_SRCSHAPE, VT_DESTSHAPE
/// @param varName 变量名
/// @param initVal 初始值
/// @param count [可选]数组长度,非数组为1
///
static int AddVar( lua_State *L )
{
Script *script = GetInst( ScriptSys ).GetScript( L );
long operType = (long) tolua_tonumber( L, 1, 0 );
VariableList *varList = ( script != NULL ? script->GetVarList( operType ) : NULL );
bool ret = false;
if( operType == Script::VT_GLOBAL )
{
// not support global variable list
varList = NULL;
}
if( varList != NULL )
{
ret = true;
long count = (long) tolua_tonumber( L, 4, 1 );
const char *varName = TOLUA_TOSTRING( varName, L, 2, "" );
long varType = VarList::VarType( varName );
if( varType == VariableList::VAR_NUM )
{
VariableList::Number val = (VariableList::Number) tolua_tonumber( L, 3, 0 );
varList->AddVar( varName, val, count );
}
else if( varType == VariableList::VAR_STRING )
{
const char *val = TOLUA_TOSTRING( val, L, 3, "" );
varList->AddVar( varName, tString( val ), count );
}
else if( varType == VariableList::VAR_GUID )
{
const CGUID *val = TOLUA_TOGUID( val, L, 3, &NULL_GUID );
varList->AddVar( varName, *val, count );
}
else
{
// argument error
ret = false;
}
}
else
{
// pop the arguments.
int top = lua_gettop( L );
lua_settop( L, top - 3 );
}
lua_pushboolean( L, ret ? 1 : 0 );
return 1;
}