lua-users home
lua-l archive

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




On 2/9/06, Doug Rogers <rogers@innocon.com> wrote:
Joseph Stewart wrote:

> If I added base#number support to Lua, would there be interest in some
> kind of string.format extension for base output as well? I know I'd use
> it. I'm not sure how to extend the sprintf style output specifier in a
> sane way, though.
> %b# ... where '#' is from 2 to 36

To me conversion from a base to a string is a minor thing. The only
bases I would find useful are decimal, hexadecimal, and binary. Your
idea about the arbitrary base using base#number sounds a lot like the
Ada way. It is very convenient, especially when the use '_' characters
is allowed within the number portion. It makes bit fields easy to delineate.

I like the idea of NO-OP underscores...

But if I had my way, I'd rather see hexadecimal escape sequences in
strings, especially now that 0xXX is supported through the C99 strtoul()
call. That would make my life a tad easier. Of course there are
workarounds for everything (including a patch to the language to support
it).

Yeah, I spend most of my time doing 'C' work, so 0xDEADFACE is familiar... yet I've always wondered why no binary constant specifier made it into the language spec, and really who uses octal notation anyway...

And even before hexadecimal escape sequences, my first and second
choices for Lua improvements are (1) an integer type and (2) bitwise
operators for integers or even for the existing Lua number type,
whatever it happens to be. Either could be implemented without the other.

I've been happy with Reuben Thomas' bitlib, but I can see in the interest of efficiency, a set of native binary operators could give a boost.

What is driving my desire for an integer type is my embedded target
where I have software floating point only. My scripts run very slowly to
do what should be simple things. I don't want to give up the ability to
use floating point (there are still plenty of uses for it), but I'd like
to be able to avoid the overhead when necessary.

I've build integer-only versions of Lua, but I'd never thought of supporting both types simultaneously for this reason. I like it... while I was working on the BASE#NUMBER hack to  lua-5.0.2, I had a brief moment where I thought I might add an Integer type, but didn't feel like doing that much work. Maybe time to reconsider it.

But that's just my particular corner of an obscure part of the Lua universe.

Some other idle musings...

I like the idea of setting aside a bunch of operators that have no
meaning in the current instance of Lua. This would require an
enumeration of all the possible operators in the VM. The language could
define any undefined operator (such as, say, '^^') to return its left
argument. Or something similar. This may require certain limitations on
new operators (binary versus unary) and precedence rules might also be
necessary. But I like the idea of being able to replace any operator via
the metatable.

Also, rather than using '__mul' in the metatable, use the operator
string '*' itself.

Alas, I need to get so many other things taken care of before I can
dedicate more time to hacking the Lua VM.

I understand your dilemma. If you get further on some of your ideas, drop me a line!

Doug

--
--__-__-____------_--_-_-_-___-___-____-_--_-___--____
Doug Rogers - ICI - V:703.893.2007x220 www.innocon.com
-_-_--_------____-_-_-___-_--___-_-___-_-_---_--_-__-_