[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: next == pairs({})?
- From: Rob Hoelz <rob@...>
- Date: Thu, 24 Sep 2009 15:55:30 -0500
This is how pairs and next get registered (not verbatim):
lua_pushcfunction(L, luaB_next);
lua_pushcclosure(L, luaB_pairs, 1);
lua_setglobal(L, "pairs");
lua_pushcfunction(L, luaB_next);
lua_setglobal(L, "next");
luaB_pairs returns its first upvalue, which is a TValue wrapping
luaB_next. _G.next is another TValue, distinct from pairs' upvalue,
that also wraps luaB_next. If there were a function tocfunction(f)...
tocfunction(pairs) == tocfunction(next)
would be true.
-Rob
Am Thu, 24 Sep 2009 16:47:45 -0400
schrieb Jim Pryor <lists+lua@jimpryor.net>:
> In my lua interpreter, the first value returned by pairs({}) is not
> the same function as is assigned to next. At first I thought this
> might be because some library I have installed, but I see this
> behavior also if I uninstall all my lua add-on packages, and also if
> I start lua with LUA_PATH set to the empty string.
>
> > return next
> function: 0x1x52c600
> > return (pairs({}))
> function: 0x1x52c0e0
>
> Why is that? Is one of these a wrapper around the other? Which wraps
> the other and what is the wrapper doing?
>
> >From a casual inspection of lbaselib.c in the lua sources, I can't
> figure out why it's happening, either. Even the source looks like the
> first return value of pairs({}) should be next.
>
> I'm using my own build of lua on x86_64 linux, in case that matters.
>
Attachment:
signature.asc
Description: PGP signature