lua-users home
lua-l archive

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


I am saying that it is out of my control, as it is done by code I did not write.  So the metatable check works but the subsequent rawlen() fails.  luaL_checkudata() does not prevent a user from causing a segfault if they match up your mt with a very small userdata...

Also, Coda, I said in my original posting that would seem a bit unclear to store the hidden userdata within a table to associate to the userdata that gets exposed.  It makes its access weirder and a bit unclear to someone reviewing the code later -- I'm just wondering if pucrio can comment on if this would be a simple addition that would make sense.  If anything, storing it in a table would mean using more memory (assuming this suggestion is possible).


On Mon, Dec 2, 2013 at 3:36 AM, Sean Conner <sean@conman.org> wrote:
It was thus said that the Great Sir Pogsalot once stated:
> I did originally do that, but then the receiving code I would pass this
> larger userdata object to would call lua_rawlen() and then the game was
> over :(  I need these 2 userdata to be bound through collection but
> entirely separate otherwise (I make this fun).

  I guess I don't understand the requirements then.

  If you are using metatables to provide typechecking, then:

        struct myfoo *pmyfoo = luaL_checkudata(L,idx,TYPE_FOO);

and

        struct foo *pfoo = luaL_checkudata(L,idx,TYPE_FOO);

will work (as long as 'struct foo' is the first element of 'struct myfoo').
In the later case, the code doesn't know (nor care) that the memory for pfoo
is larger than normal.  Why would you call lua_rawlen() when you know what
you have?  (unless you aren't using metatables for typechecking and are
solely relying in the raw size)

  -spc