lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Oups.
to fix it, around lparser.c:824, change to

static const struct {
  lu_byte left;  /* left priority for each binary operator */
  lu_byte right; /* right priority */
} priority[] = {  /* ORDER OPR */
   {6, 6}, {6, 6}, {7, 7}, {7, 7}, {7, 7},  /* `+' `-' `/' `%' */
#if defined(LUA_BITWISE_OPERATORS)
   {10, 9}, 
   {6, 6}, {6, 6}, {6, 6}, {7, 7}, {7, 7}, {7, 7}, /* `|' `&' `!' `<<' `>>' `\' */
   {5, 4},                 /* power and concat (right associative) */
#else
   {10, 9}, {5, 4},                 /* power and concat (right associative) */
#endif
   {3, 3}, {3, 3},                  /* equality and inequality */
   {3, 3}, {3, 3}, {3, 3}, {3, 3},  /* order */
   {2, 2}, {1, 1}                   /* logical (and/or) */
};

I'll upgrade the patch to 5.1.2 including the fix as soon as I have time.

I've also made a patch which is a bit different. Instead of modifying the number type, it introduces a hex type with a conversion function tohex() from a number. The advantage is that it is implemented with a unsigned long long so 64 bits are useable instead of being bound to 53 bits.
I also wonder if I can change the ^ semantic so that it becomes a xor for hex types instead of introducing ^^. Do you think this approach could suit better to your needs?

-----Original Message-----
From: lua-bounces@bazar2.conectiva.com.br [mailto:lua-bounces@bazar2.conectiva.com.br] On Behalf Of Jesús Ruiz de Infante
Sent: Friday, April 27, 2007 11:24 AM
To: Lua list
Subject: bitwise operators patch breaks Lua operator precedence

Hi all!

The bitwise operators patch by Thierry Grellier breaks Lua operator 
precedence:

$ lua
Lua 5.1.1 patched (added | & ^^ << >> ~ \ !=)  Copyright (C) 1994-2006 
Lua.org,
PUC-Rio
 > = 1 + 2^2 -- interpreted as (1 + 2)^2 instead of 1 + (2^2)
9 -----------> should be 5
 >


I'm using Lua 5.1.1 as a base and the 
http://lua-users.org/files/wiki_insecure/power_patches/5.1/newluaoperators.patch
from 2006-Oct-10


Anyway, I have found the patch very useful when interfacing with binary 
data.

Thanks,

-- 
Mit freundlichen Grüßen

Jesus Ruiz de Infante
(Entwicklung)
HALE electronic GmbH
Eugen-Müller-Straße 18, 5020 Salzburg, Austria
Tel:  +43 (662) 439011 0
Fax:  +43 (662) 439011 9
jesus.ruizdeinfante@hale.at
Firmenbuchnummer: FN 66801m HG Salzburg



--
Scanned by MailScanner.