title: lua metatable __lt __le __eq forced boolean conversion of return value
body: <p>Overloading <code>__eq</code>, <code>__lt</code>, and <code>__le</code> in a metatable always converts the returning value to a boolean.</p>
  
  <p>Is there a way to access the actual return value?</p>
  
  <p>This would be used in the following little lua script to create an expression tree for an argument</p>
  
  <p>usage: </p>
  
  <pre><code>print(_.a + _.b - _.c * _.d + _.a) 
           -&gt; prints "(((a+b)-(c*d))+a)" which is perfectly what I would like to have
  </code></pre>
  
  <p>but it doesn't work for <code>print(_.a == _.b)</code> since the return value gets converted to a boolean</p>
  
  <p>ps: print should be replaced later with a function processing the expression tree</p>
  
  <p>-- snip from lua script --</p>
  
  <pre><code>function binop(op1,op2, event)
      if op1[event] then return op1[event](op1, op2) end
      if op2[event] then return op2[event](op1, op2) end
      return nil
  end
  
  function eq(op1, op2)return binop(op1,op2, "eq") end
  ...
  function div(op1, op2)return binop(op1,op2, "div") end
  
  function exprObj(tostr)
      expr =  { eq = binExpr("=="), lt = binExpr("&lt;"), le = binExpr("&lt;="), add = binExpr("+"), sub=binExpr("-"), mul = binExpr("*"), div= binExpr("/") }
      setmetatable(expr,  { __eq = eq, __lt = lt, __le = le, __add = add, __sub = sub, __mul = mul, __div = div, __tostring = tostr })
      return expr
  end
  
  function binExpr(exprType)
      function binExprBind(lhs, rhs)
          return exprObj(function(op) return "(" .. tostring(lhs) ..  exprType .. tostring(rhs) .. ")" end)
      end
      return binExprBind
  end
  
  function varExpr(obj, name)
      return exprObj(function() return name end)
  end
  
  _ = {}
  setmetatable(_, { __index = varExpr })
  </code></pre>
  
  <p>-- snap --</p>
  
  <p>Modifing the lua vm IS an option, however it would be nice if I could use an official release</p>