예제 #1
0
CLuaArgument* CLuaArguments::PushTable ( CLuaArguments * table )
{
    CLuaArgument* pArgument = new CLuaArgument (  );
    pArgument->Read(table);
    m_Arguments.push_back ( pArgument );
    return pArgument;
}
예제 #2
0
bool CClientTask::ReadParameters ( lua_State* luaVM, int iTableIndex, bool bClear )
{
    // Clear the old parameters first
    if ( bClear )
    {
        m_Keys.clear ();
        m_Values.clear ();
    }

    // Grab the stack position for the table after we've pushed data to it.
    // This is table index - 1 if the index is negative, otherwize it stays
    // the same.
    int iNewTableIndex;
    if ( iTableIndex < 0 )
        iNewTableIndex = iTableIndex - 1;
    else
        iNewTableIndex = iTableIndex;

    // Not a table? Bad
    if ( !lua_istable ( luaVM, iTableIndex ) )
    {
        return false;
    }

    // Loop through our table, beginning at the first key
    lua_pushnil ( luaVM );
    while ( lua_next ( luaVM, iNewTableIndex ) != 0 )
    {
        // Get the key and value
        const char* szKey = lua_tostring ( luaVM, -2 );
        CLuaArgument Value;
        Value.Read ( luaVM, -1 );

        // Got both a key and a value?
        if ( szKey )
        {
            // If we cleared, just add them
            if ( bClear )
            {
                // Store it
                m_Keys.push_back ( szKey );
                m_Values.push_back ( Value );
            }
            else
            {
                // Otherwize merge it in
                SetParameter ( szKey, Value );
            }

            // Remove the value and keep the key for the next iteration
            lua_pop ( luaVM, 1 );
        }
        else
        {
            // Remove the value and keep the key for the next iteration
            lua_pop ( luaVM, 1 );
            return false;
        }
    }

    // Success
    return true;
}