lua-users home
lua-l archive

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


I agree

You can see that on tonumber() too - Lua 4.0:

the declaration

   a=tonumber(gsub("a is 10", "a is (%d*)", "%1"), nil)

does not work, because an error message says that the argument #2 must be a
number
if you just write

   a=tonumber(gsub("a is 10", "a is (%d*)", "%1"))

it won't work, sice Lua 4.0 passes the second return value of gsub as the
second argument to tonumber()
so now you have to do it by yourself:

   a=tonumber(gsub("a is 10", "a is (%d*)", "%1"), 10)

but this is not very nice. Lets say that you would like to redefine tonumber
so the default conversion will be to HEX:

   tonumber = function (n, b) return %tonumber(n, b or 16) end

in this case it would be better to use the first declaration to get the
number 'a' in the format you predefined

tonumber() and other Lua functions are considering 'nil' and 'LUA_NOOBJECT'
as different values, in this case they would feet well if considered as a
missing parameter

Luiz


> -----Original Message-----
> From: lua-l@tecgraf.puc-rio.br [mailto:lua-l@tecgraf.puc-rio.br]On
> Behalf Of Mauro Vezzosi
> Sent: Thursday, July 27, 2000 11:35 AM
> To: Multiple recipients of list
> Subject: nil value as gsub() 4th parameter
> 
> 
> Hi
> 
> gsub() accepts an optional 4th parameter but it requires a not nil 
> value for this parameter, if you pass it.
> Could be a good idea, for the next Lua version, to change gsub() (and 
> other functions ?) to accept a variable with nil value as 4th 
> parameter ? (Like next() from Lua 3.2 to 4.0 Alpha)
> 
> Bye
> Mauro
> 
>