lua-users home
lua-l archive

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

On 10/28/05, Tomas <> wrote:
> >   lua_pushstring(L, "newindex");
>         Have you tried "__newindex"?

Yes. As I mentioned in my original post, I tried "newindex",
"__newindex", as well as "index" and "__index". My function is never

So I don't lose the context, here is the important bits of my original
post are below. Maybe this isn't as easy as I thought it would be.


My 4.0 code looked like this:

  lua_pushcfunction(L, getglobal);
  lua_settagmethod(L, LUA_TNIL, "getglobal");

For 5.0 I tried to do this:

  lua_pushvalue(L, LUA_GLOBALSINDEX);
  lua_getmetatable(L, -1);
  lua_pushstring(L, "__newindex");
  lua_pushcfunction(L, getglobal);
  lua_settable(L, -3)

But my function never gets called. I also tried "index", "__newindex",
and "__index", but no avail.

FYI, what I am trying to do is catch statements of the form: = "MyPackage"

...where `package` hasn't been defined yet. My function will create a
table, populate a few values, and then setglobal("package") before