lua-users home
lua-l archive

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


Patrick Donnelly wrote:
On Thu, Jun 25, 2009 at 12:39 AM, Shmuel Zeigerman<shmuz@013net.net> 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.

Here is the original use case:
    if (lua_isnoneornil(L, 1)) {
        lua_createtable(L, 0, 0);
        lua_replace(L, 1);
    }
    luaL_checktype(L, 1, LUA_TTABLE);

The code above looked straightforward enough, and when it didn't work as expected, that was a surprise to me.

--
Shmuel