lua-users home
lua-l archive

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

2009/6/25 Shmuel Zeigerman <>:
> Patrick Donnelly wrote:
>> On Thu, Jun 25, 2009 at 12:39 AM, Shmuel Zeigerman<>
>> wrote:
>>> When Lua stack has one element, doing lua_replace(L,1) removes that
>>> element.
>>> (I'd expect the stack to be left unchanged.)
> [...]
>> The manual is pretty explicit about the top element being removed from
>> the stack. I don't see why this should be different for this odd use
>> case.
> Because it seems pretty unintuitive, even if it doesn't contradict with the
> manual. From the common sense point of view, replace "a" with "b" assumes
> there should be "b" in place of "a", rather then "nothing".
> And, this use case is not so odd. It is like assignment "var1 = var2", where
> var2 can be anything, var1 included.

It's not completely similar to that example, since var1 = var2 doesn't
undefine var2, while lua_replace does pop it in the normal case.

On the other hand I agree the current behaviour of lua_replace(L,
lua_gettop(L)) is counter-intuitive. IMHO it should either be a no-op
or throw an error.