Doug Currie | 2 Oct 2006 01:06
Picon

Re: 5.2 feature list?

Monday, September 11, 2006, 12:32:09 PM, Roberto Ierusalimschy wrote:

>> i have seen some lua 5.2 feature requests. is there an "official" place
>> where the feature requests are stored/tracked?

> Only the list itself.

Here is a proposal for 5.2...

It was a surprise to me that string.format()'s option "%s" did not
apply tostring() to its arguments as print() does.

This would make formatted output using, e.g., loadable numerics
libraries like decNumber, much more convenient. Of course, it would
work with any userdata or class that implemented __tostring.

So, my request is that Lua 5.2 either
- apply tostring() to non-string "%s" arguments of string.format(), or
- add a string.format option that applies tostring() to its argument,
and then performs the usual "%s" action.

If the second approach is preferred, I am not particular to any
specific character to specify this format option, though I recommend
"%m" (use Metatable's __tostring) or "%y" (stringifY) -- neither of
these is in common usage with printf as far as I know, unlike "%o"
(Object) and "%S" (wide String).

Regards,

e
(Continue reading)

John Belmonte | 2 Oct 2006 13:05
Gravatar

Re: 5.2 feature list?

Doug Currie wrote:
> So, my request is that Lua 5.2 either
> - apply tostring() to non-string "%s" arguments of string.format(), or
> - add a string.format option that applies tostring() to its argument,
> and then performs the usual "%s" action.

I'd like to see the first implemented by having lua_tostring honor
__tostring, and perhaps adding a lua_rawtostring if there is really
demand for it.

--John

Rici Lake | 2 Oct 2006 20:35

Re: 5.2 feature list?


On 2-Oct-06, at 6:05 AM, John Belmonte wrote:

> Doug Currie wrote:
>> So, my request is that Lua 5.2 either
>> - apply tostring() to non-string "%s" arguments of string.format(), or
>> - add a string.format option that applies tostring() to its argument,
>> and then performs the usual "%s" action.
>
> I'd like to see the first implemented by having lua_tostring honor
> __tostring, and perhaps adding a lua_rawtostring if there is really
> demand for it.
>
> --John
>

I don't think that's really necessary. It can easily be written 
(although the following code has not actually been tested):

/* If possible, pushes onto the stack the string coercion of the object
    at stack or pseudo index obj, and returns a pointer to the C string.
    If plen is not NULL, stores the length of the returned string in 
plen.

    If the indicated object cannot be coerced to a string, returns
    NULL, does not alter plen, and does not alter the stack.
  */
const char *my_pushstringvalue (luaState *L, int obj, size_t *plen) {
   switch (lua_type(L, obj)) {
     case LUA_TSTRING:
(Continue reading)

Glenn Maynard | 3 Oct 2006 10:32
Gravatar

Re: 5.2 feature list?

On Mon, Oct 02, 2006 at 01:35:36PM -0500, Rici Lake wrote:
> I don't think that's really necessary. It can easily be written 
> (although the following code has not actually been tested):

This wouldn't be used by libraries, though: you'd have to modify them to
use it.

I'd like luaL_typerror (or luaL_typename) to try a __type metamethod.
Currently, I have to modify it, so "number expected, got table" can
become "number expected, got Sprite".

> const char *my_pushstringvalue (luaState *L, int obj, size_t *plen) {
>   switch (lua_type(L, obj)) {
>     case LUA_TSTRING:
>     case LUA_TNUMBER:
>       lua_pushvalue(L, obj);
>     default: {
>       if (0 == luaL_callmeta(L, obj, "__string"))
>         return NULL;

Maybe for number types, too, for custom number conversions.

--

-- 
Glenn Maynard, wishing for the end of 0 == n()

Rici Lake | 2 Oct 2006 20:39

Re: 5.2 feature list?


On 2-Oct-06, at 1:35 PM, Rici Lake wrote:

> I don't think that's really necessary. It can easily be written 
> (although the following code has not actually been tested):
>

Oops

> /* If possible, pushes onto the stack the string coercion of the object
>    at stack or pseudo index obj, and returns a pointer to the C string.
>    If plen is not NULL, stores the length of the returned string in 
> plen.
>
>    If the indicated object cannot be coerced to a string, returns
>    NULL, does not alter plen, and does not alter the stack.
>  */
> const char *my_pushstringvalue (luaState *L, int obj, size_t *plen) {
>   switch (lua_type(L, obj)) {
>     case LUA_TSTRING:
>     case LUA_TNUMBER:
>       lua_pushvalue(L, obj);
         break;
>     default: {
>       if (0 == luaL_callmeta(L, obj, "__string"))
>         return NULL;
>     }
>   }
>   return lua_tolstring(L, -1, plen);
> }
(Continue reading)

Sam Roberts | 2 Oct 2006 19:29

Re: 5.2 feature list?

On Mon, Oct 02, 2006 at 07:05:17AM -0400, John Belmonte wrote:
> Doug Currie wrote:
> > So, my request is that Lua 5.2 either
> > - apply tostring() to non-string "%s" arguments of string.format(), or
> > - add a string.format option that applies tostring() to its argument,
> > and then performs the usual "%s" action.
> 
> I'd like to see the first implemented by having lua_tostring honor
> __tostring, and perhaps adding a lua_rawtostring if there is really
> demand for it.

I don't think that can be done. Remember, lua_tostring converts the Lua
value at the given index to a string.

So, calling lua_tostring() on a value that had a __tostring metamethod
would remove it from the stack, replacing it with a string. Some people
already don't like auto-coercions between number and string, can you
imagine the trouble it would cause to have your user-data auto-coerced
to strings? :-(

Sam

Glenn Maynard | 3 Oct 2006 10:38
Gravatar

Re: 5.2 feature list?

On Mon, Oct 02, 2006 at 10:29:16AM -0700, Sam Roberts wrote:
> On Mon, Oct 02, 2006 at 07:05:17AM -0400, John Belmonte wrote:
> > Doug Currie wrote:
> > > So, my request is that Lua 5.2 either
> > > - apply tostring() to non-string "%s" arguments of string.format(), or
> > > - add a string.format option that applies tostring() to its argument,
> > > and then performs the usual "%s" action.
> > 
> > I'd like to see the first implemented by having lua_tostring honor
> > __tostring, and perhaps adding a lua_rawtostring if there is really
> > demand for it.
> 
> I don't think that can be done. Remember, lua_tostring converts the Lua
> value at the given index to a string.
> 
> So, calling lua_tostring() on a value that had a __tostring metamethod
> would remove it from the stack, replacing it with a string. Some people
> already don't like auto-coercions between number and string, can you
> imagine the trouble it would cause to have your user-data auto-coerced
> to strings? :-(

Hmm, a thought: if automatic coercion for numbers was also done via this
metamethod, then you could turn them off by removing the metamethod.

(If both exist, I'd think "metamethod for tostring()" and "metamethod
for implicit coercions" would be separate metamethods, since they're
entirely different operations.)

--

-- 
Glenn Maynard
(Continue reading)

Andreas Stenius | 3 Oct 2006 08:22
Picon

Re: 5.2 feature list?

Sam Roberts skrev:
[...]
> So, calling lua_tostring() on a value that had a __tostring metamethod
> would remove it from the stack, replacing it with a string. Some people
> already don't like auto-coercions between number and string, can you
> imagine the trouble it would cause to have your user-data auto-coerced
> to strings? :-(

This is not a problem. The only place the user-data or other type will 
be replaced with a string is in the stack where the string.format 
routine collects it's arguments. The original value will remain the 
same, at another safe location in the stack.

//Andreas

Aaron Brown | 3 Oct 2006 10:09
Picon
Favicon

Re: 5.2 feature list?

Andreas Stenius wrote:

> Sam Roberts skrev:

>> Some people already don't like auto-coercions between
>> number and string, can you imagine the trouble it would
>> cause to have your user-data auto-coerced to strings? :-(
>
> This is not a problem. The only place the user-data or
> other type will be replaced with a string is in the stack
> where the string.format routine collects it's arguments.

Sam was responding to John Belmonte's suggestion that
lua_tostring honor __tostring.

--

-- 
Aaron

Doug Currie | 2 Oct 2006 19:42
Picon

Re: 5.2 feature list?

Monday, October 2, 2006, 1:29:16 PM, Sam Roberts wrote:

> On Mon, Oct 02, 2006 at 07:05:17AM -0400, John Belmonte wrote:
>> Doug Currie wrote:
>> > So, my request is that Lua 5.2 either
>> > - apply tostring() to non-string "%s" arguments of string.format(), or
>> > - add a string.format option that applies tostring() to its argument,
>> > and then performs the usual "%s" action.
>> 
>> I'd like to see the first implemented by having lua_tostring honor
>> __tostring, and perhaps adding a lua_rawtostring if there is really
>> demand for it.

> I don't think that can be done. Remember, lua_tostring converts the Lua
> value at the given index to a string.

> So, calling lua_tostring() on a value that had a __tostring metamethod
> would remove it from the stack, replacing it with a string. Some people
> already don't like auto-coercions between number and string, can you
> imagine the trouble it would cause to have your user-data auto-coerced
> to strings? :-(

Without arguing one way or the other about lua_tostring, to get my
first option:
- apply tostring() to non-string "%s" arguments of string.format()
the first couple lines of the 's' case of str_format() could be modified
as follows:

        case 's': {
          size_t l;
(Continue reading)

askok | 2 Oct 2006 15:27
Gravatar

Re: 5.2 feature list?


On Mon, 02 Oct 2006 07:05:17 -0400
  John Belmonte <john <at> neggie.net> wrote:
> Doug Currie wrote:
>> So, my request is that Lua 5.2 either
>> - apply tostring() to non-string "%s" arguments of 
>>string.format(), or
>> - add a string.format option that applies tostring() to 
>>its argument,
>> and then performs the usual "%s" action.
> 
> I'd like to see the first implemented by having 
>lua_tostring honor
> __tostring, and perhaps adding a lua_rawtostring if 
>there is really
> demand for it.
> 
> --John

Me, too.  I would regard this as a bug, in fact - is there 
a reason behind the current (lack of) functionality?

-asko

David Burgess | 2 Oct 2006 15:09
Picon

Re: 5.2 feature list?

Does anyone else have view on my wish for:
lua_load(), lua_dump() to have an extra parameter that strips the
debug symbols?

DB

David Jones | 2 Oct 2006 15:52
Picon
Favicon
Gravatar

Re: 5.2 feature list?


On 2 Oct 2006, at 14:09, David Burgess wrote:

> Does anyone else have view on my wish for:
> lua_load(), lua_dump() to have an extra parameter that strips the
> debug symbols?

I think it's a good idea.  I'd be mildly enthusiastic for it.  Also  
in the same kind of vein I'd go for some way to strip symbols from in- 
core compiled functions.  Like this:

strip(loadstring'local x,y=... return x+y')

drj

David Burgess | 2 Oct 2006 05:50
Picon

Re: 5.2 feature list?

Seems %m or %t (tostring) would be a fair incremental improvement at little
cost.

BTW. Reminder about Ricis Lake userdata improvement
http://lua-users.org/wiki/UserDataRefinement

DB

On 10/2/06, Doug Currie <doug.currie <at> gmail.com> wrote:
> Monday, September 11, 2006, 12:32:09 PM, Roberto Ierusalimschy wrote:
>
> >> i have seen some lua 5.2 feature requests. is there an "official" place
> >> where the feature requests are stored/tracked?
>
> > Only the list itself.
>
> Here is a proposal for 5.2...
>
> It was a surprise to me that string.format()'s option "%s" did not
> apply tostring() to its arguments as print() does.
>
> This would make formatted output using, e.g., loadable numerics
> libraries like decNumber, much more convenient. Of course, it would
> work with any userdata or class that implemented __tostring.
>
> So, my request is that Lua 5.2 either
> - apply tostring() to non-string "%s" arguments of string.format(), or
> - add a string.format option that applies tostring() to its argument,
> and then performs the usual "%s" action.
>
(Continue reading)

Doug Currie | 2 Oct 2006 07:40
Picon

Re: 5.2 feature list?

Sunday, October 1, 2006, 11:50:56 PM, David Burgess wrote:

> Seems %m or %t (tostring) would be a fair incremental improvement at little
> cost.

Yes. Here is the case to add in str_format()...

        case 't': {
          size_t l = strlen(form);
          form[l - 1] = 's';
          lua_getglobal(L, "tostring");
          lua_pushvalue(L, arg);
          lua_call(L, 1, 1);
          lua_replace(L,arg);
          /* fall into... */
        }
        case 's': {

Regards,

e

> On 10/2/06, Doug Currie <doug.currie <at> gmail.com> wrote:
>> Monday, September 11, 2006, 12:32:09 PM, Roberto Ierusalimschy wrote:
>>
>> >> i have seen some lua 5.2 feature requests. is there an "official" place
>> >> where the feature requests are stored/tracked?
>>
>> > Only the list itself.
>>
(Continue reading)


Gmane