Exemplo n.º 1
0
//------------------------------------------------------------------------
int CScriptBind_UIAction::GetArray( IFunctionHandler *pH, const char * elementName, int instanceID, const char* arrayName )
{
	IUIElement* pElement = GetElement( elementName, instanceID );
	if ( pElement )
	{
		const SUIParameterDesc* pArrayDesc = pElement->GetArrayDesc( arrayName );
		SUIArguments vals;
		if ( pArrayDesc && pElement->GetArray( pArrayDesc, vals ) )
		{
			SmartScriptTable res(m_pSS);
			string val;
			for (int i = 0; i < vals.GetArgCount(); ++i)
			{
				vals.GetArg(i).GetValueWithConversion(val);
				res->SetAt( i+1, val.c_str() );
			}
			return pH->EndFunction( res );
		}
		UIACTION_WARNING( "LUA: Element %s has no array %s", elementName, arrayName );
	}
	else
	{
		UIACTION_WARNING( "LUA: UIElement %s does not exist", elementName );
	}
	return pH->EndFunction( false );
}
Exemplo n.º 2
0
//------------------------------------------------------------------------
int CScriptBind_UIAction::SetArray( IFunctionHandler *pH, const char * elementName, int instanceID, const char* arrayName, SmartScriptTable values )
{
	IUIElement* pElement = GetElement( elementName, instanceID );
	if ( pElement )
	{
		const SUIParameterDesc* pArrayDesc = pElement->GetArrayDesc( arrayName );
		if ( pArrayDesc )
		{
			SUIArguments vals;
			if (SUIToLuaConversationHelper::LuaTableToUIArgs(values, vals))
			{
				bool bVarOk = true;
				if ( instanceID < 0 )
				{
					IUIElementIteratorPtr elements = pElement->GetInstances();
					while ( IUIElement* pInstance = elements->Next() )
						bVarOk &= pInstance->SetArray( pArrayDesc, vals );
				}
				else
				{
					bVarOk = pElement->SetArray( pArrayDesc, vals );
				}

				if ( bVarOk )
					return pH->EndFunction(true);
			}
			UIACTION_ERROR( "LUA: Failed to set array %s on Element %s: Invalid arguments", arrayName, elementName);
		}
		UIACTION_WARNING( "LUA: Element %s has no array %s", elementName, arrayName);
	}
	else
	{
		UIACTION_WARNING( "LUA: UIElement %s does not exist", elementName);
	}
	return pH->EndFunction(false);
}