lua-users home
lua-l archive

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

On Tue, Mar 1, 2011 at 04:40, liam mail <> wrote:
> On 1 March 2011 11:30, Gunnar Zötl <> wrote:
>> > The most frequent use of gettop and isnone in C lua libraries to
>> > modify what a function does really disturbs me.
>> Is there a source for that claim? I'd reckon that the most frequent use of
>> these is to do optional/variable arguments, and checking wether you got the
>> correct number of arguments. At least that's what I do with those.
>> > foo(nil,nil,nil) should be the same as foo(nil,nil) and foo() etc
>> Nope, it should not. Passing three nils is not the same as passing nothing
>> at all.
>> > What steps can we take to discourage the writing, and usage of libraries
>> > that do such evil?
>> Could you name a few, please?
>> Gunnar
> Actually Daurnimator does have a valid point, which maybe should require a
> note to the functions it effects.
> I would personally say that table.insert(t,1,k) and table.insert(t,k,nil)
> under Lua rules should behave the same. The problem is the function is doing
> too much and would require a separate C function which I do not think is
> going to happen. The biggest problem I see with tinsert is that extra
> parameters ie greater than three cause an error, are there any other Lua C
> functions that do not ignore extra parameters?

Personally I would have split it into two functions:
table.insert(t, k, v, ...) --insert one or more values at position k,
shifting others as necessary.
table.append(t, v, ...) --append one or mote values.

As for gettop it has its uses, but this example is what
lua_isnoneornil() is for.

Sent from my toaster.