Exemplo n.º 1
0
void lua_pushuserdata ( lua_State* luaVM, void* pData )
{
    if ( CElement* pEntity = UserDataCast < CElement > ( ( CElement* ) NULL, pData, NULL ) )
        return lua_pushelement ( luaVM, pEntity );
    if ( CPlayer* pEntity = UserDataCast < CPlayer > ( ( CPlayer* ) NULL, pData, NULL ) )
        return lua_pushelement ( luaVM, pEntity );
    else if ( CResource* pResource = UserDataCast < CResource > ( ( CResource* ) NULL, pData, NULL ) )
        return lua_pushresource ( luaVM, pResource );
    else if ( CXMLNode* pNode = UserDataCast < CXMLNode > ( ( CXMLNode* ) NULL, pData, NULL ) )
        return lua_pushxmlnode ( luaVM, pNode );
    else if ( CLuaTimer* pTimer = UserDataCast < CLuaTimer > ( ( CLuaTimer* ) NULL, pData, luaVM ) )
        return lua_pushtimer ( luaVM, pTimer );
    else if ( CLuaVector2D* pVector = UserDataCast < CLuaVector2D > ( (CLuaVector2D*) NULL, pData, luaVM ) )
        return lua_pushvector ( luaVM, *pVector );
    else if ( CLuaVector3D* pVector = UserDataCast < CLuaVector3D > ( (CLuaVector3D*) NULL, pData, luaVM ) )
        return lua_pushvector ( luaVM, *pVector );
    else if ( CLuaVector4D* pVector = UserDataCast < CLuaVector4D > ( (CLuaVector4D*) NULL, pData, luaVM ) )
        return lua_pushvector ( luaVM, *pVector );
    else if ( CLuaMatrix* pMatrix = UserDataCast < CLuaMatrix > ( (CLuaMatrix*) NULL, pData, luaVM ) )
        return lua_pushmatrix ( luaVM, *pMatrix );
    else if ( CAccount* pAccount = UserDataCast < CAccount > ( (CAccount*) NULL, pData, luaVM ) )
        return lua_pushaccount ( luaVM, pAccount );
    else if ( CAccessControlList* pACL = UserDataCast < CAccessControlList > ( (CAccessControlList*) NULL, pData, luaVM ) )
        return lua_pushacl ( luaVM, pACL );
    else if ( CAccessControlListGroup* pACLGroup = UserDataCast < CAccessControlListGroup > ( (CAccessControlListGroup*) NULL, pData, luaVM ) )
        return lua_pushaclgroup ( luaVM, pACLGroup );
    else if ( CBan* pBan = UserDataCast < CBan > ( (CBan*) NULL, pData, luaVM ) )
        return lua_pushban ( luaVM, pBan );
    else if ( CTextDisplay* pTextDisplay = UserDataCast < CTextDisplay > ( (CTextDisplay*) NULL, pData, luaVM ) )
        return lua_pushtextdisplay ( luaVM, pTextDisplay );
    else if ( CTextItem* pTextItem = UserDataCast < CTextItem > ( (CTextItem*) NULL, pData, luaVM ) )
        return lua_pushtextitem ( luaVM, pTextItem );
    else if ( CDbJobData* pQuery = UserDataCast < CDbJobData > ( (CDbJobData*) NULL, pData, luaVM ) )
        return lua_pushquery ( luaVM, pQuery );

    lua_pushobject ( luaVM, NULL, pData );
}
Exemplo n.º 2
0
int CLuaTextDefs::textCreateTextItem ( lua_State* luaVM )
{
    
    SString strText, strHorzAlign, strVertAlign;
    float fX, fY, fScale;
    int iPriority;
    SColorRGBA color ( 255, 255, 255, 255 );
    unsigned char ucShadowAlpha;

    CScriptArgReader argStream ( luaVM );
    argStream.ReadString ( strText, "" );
    argStream.ReadNumber ( fX, 0.5f );
    argStream.ReadNumber ( fY, 0.5f );

    if ( argStream.NextIsString( ) )
    {
        SString strPriority;
        argStream.ReadString ( strPriority );

        if ( strPriority == "high" )        iPriority = PRIORITY_HIGH;
        else if ( strPriority == "medium" ) iPriority = PRIORITY_MEDIUM;
        else                                iPriority = PRIORITY_LOW;

    }
    else
    {
        argStream.ReadNumber(iPriority, PRIORITY_LOW);
    }
    
    argStream.ReadNumber( color.R, 255 );
    argStream.ReadNumber( color.G, 255 );
    argStream.ReadNumber( color.B, 255 );
    argStream.ReadNumber( color.A, 255 );
    argStream.ReadNumber( fScale, 1 );
    argStream.ReadString( strHorzAlign, "left" );
    argStream.ReadString( strVertAlign, "top" );
    argStream.ReadNumber( ucShadowAlpha, 0);

    if ( !argStream.HasErrors ( ) )
    {
        unsigned char ucFormat = 0; 
        if ( strHorzAlign == "center" ) 
            ucFormat |= 0x00000001; // DT_CENTER
        else if ( strHorzAlign == "right" )
            ucFormat |= 0x00000002; // DT_RIGHT

        if ( strVertAlign == "center" )
            ucFormat |= 0x00000004; // DT_VCENTER
        else if ( strVertAlign == "bottom" )
            ucFormat |= 0x00000008; // DT_BOTTOM
        
        // Grab our virtual machine
        CLuaMain* luaMain = m_pLuaManager->GetVirtualMachine ( luaVM );
        if ( luaMain )
        {
            CTextItem* pTextItem = luaMain->CreateTextItem ( strText, fX, fY, (eTextPriority) iPriority, color, fScale, ucFormat, ucShadowAlpha );
            lua_pushtextitem ( luaVM, pTextItem );
            return 1;
        }
    }
    else
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() );


    lua_pushboolean ( luaVM, false );
    return 1;
}