lua-users home
lua-l archive

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


Perhaps I'm just being dense? I need to implement the
tag function in C. So I added this to the Lua console
sample:

  void MyInit(lua_State* L)
  {
    lua_pushcfunction(L, myFunctionTagHandler);
    lua_settagmethod(L, LUA_TTABLE, "function");
  }

  int myFunctionTagHandler(lua_State* L)
  {
    // Dump the contents of the stack    
    for (int i=0; i < lua_gettop(L); i++)
      printf("%s\n", lua_typename(L, lua_type(L,i)));

    // Check the size of the table
    printf("%d\n", lua_getn(L, 1));

    return 0;
  }


When I do this:
  myTbl = { }
  myTbl()


I get this:
  table
  0


Which is not at all what I expected from looking at
the documentation of the "function" tag. This seems
too simple a task to be getting wrong.  I've started
browsing the Lua source in the hope of finding some
clues, but any help you can give would be most
appreciated.

Thanks again,
Jason
379



--- Luiz Henrique de Figueiredo
<lhf@tecgraf.puc-rio.br> wrote:
> >Now according to the docs, when the tag handler
> gets
> >called, there should be a table on the stack
> >containing the arguments to the function, and the
> >first entry should the name of the function that
> was
> >called.
> 
> No, the "function" tag method receives all arguments
> plus the value that
> triggered the event, and the value comes first.
> If you want all these to go into a table, define
> your tag method as vararg.
> 
> Try this:
> 
>  someTbl = { }
>  print(someTbl)
>  settagmethod(tag(someTbl), "function", function
> (...) foreachi(arg,print) end)
>  someTbl(10,20)
> 
> --lhf
> 
> 
> 


__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/