本文整理汇总了C++中CScriptArgReader类的典型用法代码示例。如果您正苦于以下问题:C++ CScriptArgReader类的具体用法?C++ CScriptArgReader怎么用?C++ CScriptArgReader使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CScriptArgReader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: argStream
int CLuaFunctionDefs::GetClothesByTypeIndex ( lua_State* luaVM )
{
unsigned char ucType = 0;
unsigned char ucIndex = 0;
CScriptArgReader argStream ( luaVM );
argStream.ReadNumber ( ucType );
argStream.ReadNumber ( ucIndex );
if ( !argStream.HasErrors ( ) )
{
SString strTexture, strModel;
if ( CStaticFunctionDefinitions::GetClothesByTypeIndex ( ucType, ucIndex, strTexture, strModel ) )
{
lua_pushstring ( luaVM, strTexture );
lua_pushstring ( luaVM, strModel );
return 2;
}
}
else
m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() );
lua_pushboolean ( luaVM, false );
return 1;
}
示例2: argStream
int CLuaFunctionDefs::UtfSeek ( lua_State* luaVM )
{
SString strInput = "";
int iPos = 0;
CScriptArgReader argStream ( luaVM );
argStream.ReadString ( strInput );
argStream.ReadNumber ( iPos );
if ( !argStream.HasErrors ( ) )
{
std::wstring strUTF = MbUTF8ToUTF16(strInput);
if ( iPos <= static_cast < int >(strUTF.size()) && iPos >= 0 )
{
strUTF = strUTF.substr(0,iPos);
lua_pushnumber ( luaVM, UTF16ToMbUTF8(strUTF).size() );
return 1;
}
}
else
m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );
lua_pushboolean ( luaVM, false );
return 1;
}
示例3: argStream
int CLuaFunctionDefs::PlayMissionAudio ( lua_State* luaVM )
{
CElement* pElement;
CVector vecPosition;
unsigned short usSlot;
CScriptArgReader argStream ( luaVM );
argStream.ReadUserData ( pElement );
argStream.ReadNumber ( usSlot );
if ( argStream.NextCouldBeNumber () )
{
argStream.ReadVector3D ( vecPosition );
if ( !argStream.HasErrors () )
{
if ( CStaticFunctionDefinitions::PlayMissionAudio ( pElement, &vecPosition, usSlot ) )
{
lua_pushboolean ( luaVM, true );
return 1;
}
}
else
m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );
}
else if ( !argStream.HasErrors () )
{
if ( CStaticFunctionDefinitions::PlayMissionAudio ( pElement, NULL, usSlot ) )
{
lua_pushboolean ( luaVM, true );
return 1;
}
}
else
m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );
lua_pushboolean ( luaVM, false );
return 1;
}
示例4: argStream
int CLuaFileDefs::fileWrite ( lua_State* luaVM )
{
// string fileWrite ( file, string [, string2, string3, ...] )
CScriptFile* pFile;
SString strMessage;
CScriptArgReader argStream ( luaVM );
argStream.ReadUserData ( pFile );
argStream.ReadString ( strMessage );
if ( !argStream.HasErrors ( ) )
{
// While we're not out of string arguments
long lBytesWritten = 0;
long lArgBytesWritten = 0;
do
{
unsigned long ulDataLen = strMessage.length ( );
// Write it and add the bytes written to our total bytes written
lArgBytesWritten = pFile->Write ( ulDataLen, strMessage.c_str ( ) );
if ( lArgBytesWritten == -1 )
{
m_pScriptDebugging->LogBadPointer ( luaVM, "file", 1 );
lua_pushnil ( luaVM );
return 1;
}
lBytesWritten += lArgBytesWritten;
if ( !argStream.NextIsString ( ) )
break;
argStream.ReadString ( strMessage );
}
while ( true );
// Inform file verifier
if ( lBytesWritten > 0 )
g_pClientGame->GetResourceManager()->OnFileModifedByScript( pFile->GetAbsPath(), "fileWrite" );
// Return the number of bytes we wrote
lua_pushnumber ( luaVM, lBytesWritten );
return 1;
}
else
m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() );
lua_pushnil ( luaVM );
return 1;
}
示例5: argStream
int CLuaFunctionDefs::LoadBrowserURL ( lua_State* luaVM )
{
// bool loadBrowserURL ( browser webBrowser, string url [, string postData = "", bool postURLEncoded = true ] )
CClientWebBrowser* pWebBrowser; SString strURL; SString strPostData; bool bURLEncoded;
CScriptArgReader argStream ( luaVM );
argStream.ReadUserData ( pWebBrowser );
argStream.ReadString ( strURL );
argStream.ReadString ( strPostData, "" );
argStream.ReadBool ( bURLEncoded, true );
if ( !argStream.HasErrors () )
{
// Are we dealing with a remote website?
if ( strURL.substr ( 0, 7 ) == "http://" || strURL.substr ( 0, 8 ) == "https://" )
{
bool isLocalURL = strURL.substr ( 0, 11 ) == "http://mta/";
if ( pWebBrowser->IsLocal () != isLocalURL )
{
lua_pushboolean ( luaVM, false );
return 1;
}
lua_pushboolean ( luaVM, pWebBrowser->LoadURL ( strURL, !isLocalURL, strPostData, bURLEncoded ) );
return 1;
}
// Are we dealing with a local website? If so, parse resource path. Otherwise, return false and load nothing
// Todo: Add an ACL right which is necessary to load local websites or websites in general
CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM );
if ( pLuaMain )
{
SString strAbsPath;
CResource* pResource = pLuaMain->GetResource ();
if ( CResourceManager::ParseResourcePathInput ( strURL, pResource, strAbsPath ) && pWebBrowser->IsLocal () )
{
// Output deprecated warning, TODO: Remove this at a later point
m_pScriptDebugging->LogWarning ( luaVM, "This URL scheme is deprecated and may not work in future versions. Please consider using http://mta/* instead. See https://wiki.mtasa.com/wiki/LoadBrowserURL for details" );
lua_pushboolean ( luaVM, pWebBrowser->LoadURL ( "mtalocal://" + strURL, false, strPostData, bURLEncoded ) );
return 1;
}
}
}
else
m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );
lua_pushboolean ( luaVM, false );
return 1;
}
示例6: MinServerReqCheck
//
// Check min server is correct
//
void MinServerReqCheck ( CScriptArgReader& argStream, const char* szVersionReq, const char* szReason )
{
CLuaMain* pLuaMain = g_pGame->GetLuaManager()->GetVirtualMachine ( argStream.m_luaVM );
if ( pLuaMain )
{
CResource* pResource = pLuaMain->GetResource();
if ( pResource )
{
if ( pResource->GetMinServerReqFromMetaXml () < szVersionReq )
{
#if MTASA_VERSION_TYPE == VERSION_TYPE_RELEASE
argStream.SetVersionWarning ( szVersionReq, "server", szReason );
#endif
}
}
}
}
示例7: argStream
int CLuaFunctionDefs::PlaySound ( lua_State* luaVM )
{
SString strSound = "";
CVector vecPosition;
CScriptArgReader argStream ( luaVM );
argStream.ReadString ( strSound );
if ( !argStream.HasErrors() )
{
CLuaMain * luaMain = m_pLuaManager->GetVirtualMachine ( luaVM );
if ( luaMain )
{
CResource* pResource = luaMain->GetResource();
if ( pResource )
{
SString strFilename;
bool bIsURL = false;
if ( CResourceManager::ParseResourcePathInput( strSound, pResource, strFilename ) )
strSound = strFilename;
else
bIsURL = true;
// ParseResourcePathInput changes pResource in some cases e.g. an invalid resource URL - crun playSound( ":myNotRunningResource/music/track.mp3" )
// Fixes #6507 - Caz
if ( pResource )
{
bool bLoop = false;
if ( argStream.NextIsBool ( ) )
{
argStream.ReadBool ( bLoop );
}
CClientSound* pSound = CStaticFunctionDefinitions::PlaySound ( pResource, strSound, bIsURL, bLoop );
if ( pSound )
{
// call onClientSoundStarted
CLuaArguments Arguments;
Arguments.PushString ( "play" ); // Reason
pSound->CallEvent ( "onClientSoundStarted", Arguments, false );
lua_pushelement ( luaVM, pSound );
return 1;
}
}
}
}
}
else
m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() );
lua_pushboolean ( luaVM, false );
return 1;
}
示例8: argStream
int CLuaFunctionDefs::XMLNodeSetAttribute ( lua_State* luaVM )
{
// pNode, Attribute Name, Value
CXMLNode* pNode = NULL;
SString strAttributeName = "";
SString strAttributeValue = "";
CScriptArgReader argStream ( luaVM );
argStream.ReadUserData ( pNode );
argStream.ReadString ( strAttributeName );
argStream.ReadString ( strAttributeValue, "" );
if ( !argStream.HasErrors ( ) )
{
if ( pNode )
{
// Are we going to set it to a value?
if ( argStream.NextCouldBeString( -1 ) )
{
// Write the node
CXMLAttribute* pAttribute = pNode->GetAttributes ().Create ( strAttributeName );
if ( pAttribute )
{
pAttribute->SetValue ( strAttributeValue );
lua_pushboolean ( luaVM, true );
return 1;
}
}
else
{
// Delete the attribute if it exists
CXMLAttribute* pAttribute = pNode->GetAttributes ().Find ( strAttributeName );
if ( pAttribute )
{
delete pAttribute;
lua_pushboolean ( luaVM, true );
return 1;
}
}
}
}
else
m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() );
lua_pushboolean ( luaVM, false );
return 1;
}
示例9: argStream
int CLuaFxDefs::fxAddGlass ( lua_State* luaVM )
{
// bool fxAddGlass ( float posX, float posY, float posZ, [int colorR=255, int colorG=0, int colorB=0, int colorA=255, float scale=1.0, int count=1] )
// Verify types
CVector vecPosition;
RwColor rwColor;
rwColor.r = 255;
rwColor.g = 0;
rwColor.b = 0;
rwColor.a = 255;
float fScale = 1.0f;
int iCount = 1;
CScriptArgReader argStream ( luaVM );
argStream.ReadVector3D ( vecPosition );
argStream.ReadNumber ( rwColor.r, 255 );
argStream.ReadNumber ( rwColor.g, 0 );
argStream.ReadNumber ( rwColor.b, 0 );
argStream.ReadNumber ( rwColor.a, 255 );
argStream.ReadNumber ( fScale, 1.0f );
argStream.ReadNumber ( iCount, 1 );
if ( !argStream.HasErrors ( ) )
{
if ( CStaticFunctionDefinitions::FxAddGlass ( vecPosition, rwColor, fScale, iCount ) )
{
lua_pushboolean ( luaVM, true );
return 1;
}
}
else
m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() );
// Failed
lua_pushboolean ( luaVM, false );
return 1;
}
示例10: argStream
int CLuaFunctionDefs::AddAccount ( lua_State* luaVM )
{
// account addAccount ( string name, string pass[, bool allowCaseVariations = false ] )
SString strName; SString strPassword; bool bAllowCaseVariations;
CScriptArgReader argStream ( luaVM );
argStream.ReadString ( strName );
argStream.ReadString ( strPassword );
argStream.ReadBool ( bAllowCaseVariations, false );
if ( !argStream.HasErrors () )
{
if ( !bAllowCaseVariations )
{
// Message for new behaviour
SString strCaseVariation = m_pAccountManager->GetActiveCaseVariation( strName );
if ( !strCaseVariation.empty() )
argStream.SetCustomError ( SString( "Already an account using a case variation of that name ('%s')", *strCaseVariation ) );
}
if ( !argStream.HasErrors () )
{
CAccount* pAccount;
if ( ( pAccount = CStaticFunctionDefinitions::AddAccount ( strName, strPassword ) ) )
{
lua_pushaccount ( luaVM, pAccount );
return 1;
}
}
}
if ( argStream.HasErrors () )
m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );
lua_pushboolean ( luaVM, false );
return 1;
}
示例11: argStream
int CLuaMatrixDefs::Create ( lua_State* luaVM )
{
CMatrix matrix;
CScriptArgReader argStream ( luaVM );
if ( argStream.NextIsVector3D () )
{
CVector vecPosition;
argStream.ReadVector3D ( vecPosition );
if ( argStream.NextIsVector3D () )
{
CVector vecRotation;
argStream.ReadVector3D ( vecRotation );
ConvertDegreesToRadiansNoWrap ( vecRotation );
matrix = CMatrix ( vecPosition, vecRotation );
}
else
{
matrix = CMatrix ( vecPosition );
}
}
else if ( argStream.NextIsUserDataOfType<CLuaMatrix> () )
{
argStream.ReadMatrix ( matrix );
matrix = CMatrix ( matrix );
}
else if ( !argStream.NextIsNone() ) {
argStream.SetCustomError ( "Expected vector3, matrix or nothing" );
m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );
lua_pushboolean ( luaVM, false );
return 1;
}
lua_pushmatrix ( luaVM, matrix );
return 1;
}
示例12: argStream
int CLuaCameraDefs::setCameraMatrix ( lua_State* luaVM )
{
// bool setCameraMatrix ( player thePlayer, float positionX, float positionY, float positionZ [, float lookAtX, float lookAtY, float lookAtZ, float roll = 0, float fov = 70 ] )
CElement* pPlayer; CVector vecPosition; CVector vecLookAt; float fRoll; float fFOV;
CScriptArgReader argStream ( luaVM );
argStream.ReadUserData ( pPlayer );
if ( argStream.NextIsUserDataOfType <CLuaMatrix> () ) {
CLuaMatrix* pMatrix;
argStream.ReadUserData( pMatrix );
vecPosition = pMatrix->GetPosition ();
vecLookAt = pMatrix->GetRotation ();
}
else
{
argStream.ReadVector3D ( vecPosition );
argStream.ReadVector3D ( vecLookAt, CVector () );
}
argStream.ReadNumber ( fRoll, 0.0f );
argStream.ReadNumber ( fFOV, 70.0f );
if ( !argStream.HasErrors () )
{
if ( fFOV <= 0.0f || fFOV >= 180.0f )
fFOV = 70.0f;
if ( CStaticFunctionDefinitions::SetCameraMatrix ( pPlayer, vecPosition, &vecLookAt, fRoll, fFOV ) )
{
lua_pushboolean ( luaVM, true );
return 1;
}
}
else
m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );
lua_pushboolean ( luaVM, false );
return 1;
}
示例13: argStream
int CLuaVector4Defs::Pow ( lua_State* luaVM )
{
CLuaVector4D* pVector1 = NULL;
CLuaVector4D* pVector2 = NULL;
CScriptArgReader argStream ( luaVM );
argStream.ReadUserData ( pVector1 );
if ( argStream.NextIsNumber () )
{
float fValue = 0.0f;
argStream.ReadNumber ( fValue );
CVector4D vector ( *pVector1 );
vector.fX = pow ( vector.fX, fValue );
vector.fY = pow ( vector.fY, fValue );
vector.fZ = pow ( vector.fZ, fValue );
vector.fW = pow ( vector.fW, fValue );
lua_pushvector ( luaVM, vector );
return 1;
}
else
{
argStream.ReadUserData ( pVector2 );
if ( !argStream.HasErrors () )
{
CVector4D vector ( *pVector1 );
vector.fX = pow ( vector.fX, pVector2->fX );
vector.fY = pow ( vector.fY, pVector2->fY );
vector.fZ = pow ( vector.fZ, pVector2->fZ );
vector.fW = pow ( vector.fW, pVector2->fW );
lua_pushvector ( luaVM, vector );
return 1;
}
else
{
m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() );
}
}
lua_pushboolean ( luaVM, false );
return 1;
}
示例14: argStream
int CLuaRadarAreaDefs::CreateRadarArea ( lua_State* luaVM )
{
// radararea createRadarArea ( float leftX, float bottomY, float sizeX, float sizeY, [ int r = 255, int g = 0, int b = 0, int a = 255, element visibleTo = getRootElement() ] )
CVector2D vecPosition; CVector2D vecSize; float dRed; float dGreen; float dBlue; float dAlpha;
CScriptArgReader argStream ( luaVM );
argStream.ReadVector2D ( vecPosition );
argStream.ReadVector2D ( vecSize );
argStream.ReadNumber ( dRed, 255 );
argStream.ReadNumber ( dGreen, 0 );
argStream.ReadNumber ( dBlue, 0 );
argStream.ReadNumber ( dAlpha, 255 );
if ( !argStream.HasErrors () )
{
CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM );
CResource* pResource = pLuaMain ? pLuaMain->GetResource () : NULL;
if ( pResource )
{
SColorARGB color ( dAlpha, dRed, dGreen, dBlue );
// Create it
CClientRadarArea* pRadarArea = CStaticFunctionDefinitions::CreateRadarArea ( *pResource, vecPosition, vecSize, color );
if ( pRadarArea )
{
CElementGroup * pGroup = pResource->GetElementGroup ();
if ( pGroup )
{
pGroup->Add ( (CClientEntity*) pRadarArea );
}
lua_pushelement ( luaVM, pRadarArea );
return 1;
}
}
}
else
m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );
lua_pushboolean ( luaVM, false );
return 1;
}
示例15: argStream
int CLuaFileDefs::fileRead ( lua_State* luaVM )
{
// string fileRead ( file theFile, int count )
CScriptFile* pFile; unsigned long ulCount;
CScriptArgReader argStream ( luaVM );
argStream.ReadUserData ( pFile );
argStream.ReadNumber ( ulCount );
if ( !argStream.HasErrors () )
{
if ( ulCount > 0 )
{
// Allocate a buffer to read the stuff into and read some shit into it
char* pReadContent = new char [ulCount + 1];
long lBytesRead = pFile->Read ( ulCount, pReadContent );
if ( lBytesRead != -1 )
{
// Push the string onto the lua stack. Use pushlstring so we are binary
// compatible. Normal push string takes zero terminated strings.
lua_pushlstring ( luaVM, pReadContent, lBytesRead );
}
else
{
m_pScriptDebugging->LogBadPointer ( luaVM, "file", 1 );
lua_pushnil ( luaVM );
}
// Delete our read content. Lua should've stored it
delete [] pReadContent;
// We're returning the result string
return 1;
}
else
{
// Reading zero bytes from a file results in an empty string
lua_pushstring ( luaVM, "" );
return 1;
}
}
if ( argStream.HasErrors () )
m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );
// Error
lua_pushnil ( luaVM );
return 1;
}