[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Bitwsie operators in Lua
- From: Sam Roberts <sroberts@...>
- Date: Tue, 20 Jun 2006 15:05:20 -0700
On Mon, Jun 19, 2006 at 10:28:25AM +0100, Gavin Wraith wrote:
> > 3. This seems like a very basic and popular language feature,
> > what are the reasons for not adding it to the core language until
> > now?
> To answer 3, Mike, the reasons are that Lua is such a flexible
> package that the type of number used is very much up to the
> individual implementor. For example, my OS is specific to the
> ARM, and most users of it do not have on-processor floating point
> operations provided. That is why the RISC OS distribution, RiscLua
> (http://www.wra1th.plus.com/lua/) uses 32 bit integers for the
> Lua_Number type. In this case extra operators &,|,^^,~,<<,>> are
> provided, extending the standard Lua VM. You can download the
> sources from my site, if you want to see the details. Look
> for the stuff that is #ifdefined by GCW_BIT.
I have found this to be a source of trouble in using lua. That you get
to/have to choose the type of number is fine. That there is only once
kind of number and it is assumed not to support bitwise operations is
not so fine.
Also, I've had problems with the assumption that there is only one kind
of number - you get to choose the specific representation, but there is
still only once kind. Still haven't figured out if its possible to
implement a uint64 numeric type in lua that "plays well" with the other
types. Particularly, its hard to have numeric literals for a type other
than the default, we've used strings:
Any suggestions of where I can find examples of luas with a large
integral AND a large floating point numeric type?
Listening to this thread, I have to say I still support the addition of
bitwise operators. Implementing new libraries in order to use lua is
both a necessity and strength of lua, getting to choose the numeric type
is a strength, having to hack the VM and extend the opcodes in order to
get a bitshift operator.... not a strength.
Is the trouble that the lua source make a reasonable effort to only have
source that works equally as well if lua_Number is typedefed to long or
to double, and that bit wise operators involve casting back and forth
to a (possibly) 2nd numeric type if lua_Number is floating?
Anyhow, if someone has a "pure" bitwise operators patch somewhere, that
would be nice, too. Maybe even in extras? It seems like the ones around
tend to be entangled with various other bits of functionality.