Monday, December 13, 2010

LUA: Operator Precedence

Operator precedence in Lua follows the table below, from the higher to the lower priority:



      ^
             not  - (unary)
             *   /
             +   -
             ..
             <   >   <=  >=  ~=  ==
             and
             or


All binary operators are left associative, except for `^´ (exponentiation) and `..´ (concatenation), which are right associative. Therefore, the following expressions on the left are equivalent to those on the right:



    a+i < b/2+1      <-->   (a+i) < ((b/2)+1)
    5+x^2*8          <-->   5+((x^2)*8)
    a < y and y <= z <-->   (a < y) and (y <= z)
    -x^2             <-->   -(x^2)
    x^y^z            <-->   x^(y^z)

When in doubt, always use explicit parentheses. It is easier than looking up in the manual and probably you will have the same doubt when you read the code again.

  
  
  

Thursday, December 2, 2010

Arrow Code

Thanks Nihal for your first contribution on Limbeshwar's blog, and here's an abstract example ;)

if (ui->exDirChkBox->isChecked()){
    for (int j = 0; j < dirExclLst.count(); j++){
            for(int k = 0; k < dirList.count(); k++){
                QString strDrv = dirList[k].fileName();
                QString exlLstName = dirExclLst[j];
                if (strDrv == exlLstName){
                    dirList.removeAt(k);
                }else{
                //Do Nothing
                }
            }
    }
}

Arrow Code

Welcome to the world of arrows.

Nihal Kenkre: Arrow code