[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Testing 5.1, ouch
- From: LEGO <luis.ontanon@...>
- Date: Sat, 25 Feb 2006 13:33:00 +0100
On 2/25/06, Luiz Henrique de Figueiredo <lhf@tecgraf.puc-rio.br> wrote:
> > No, you are right but at this point:
> >
> > int x_or_y() {
> > if (lual_checkudata(L,i,"X")) {
> > /* ... */
> > } else if (lual_checkudata(L,i,"Y")) {
> > /* ... */
> > } else {
> > /* ... */
> > }
> > }
> > cannot be done anymore.
>
> I never felt the need for testing two types in the same code.
Have at least three of this in my code...
Either arguments that are optional (Xopt,Yopt,Z) so if they aren't
there they are just skipped, or a function that can take either X or
Y.
I have both cases.
> > This now has to be done in a *VERY* cumbersome way either declaring
> > handlers for and doing pcalls for every check or adding a "__type"
> > index to the metatable and test it. Neither one is a simple change,
> > both are complex changes. :-(
>
> Or you can copy luaL_checkudata from lauxlib.c and adapt it to your needs.
> I guess the code below would work for you. It's a one-line change:
> LUALIB_API void *luaL_checkudata (lua_State *L, int ud, const char *tname) {
> void *p = lua_touserdata(L, ud);
> lua_getfield(L, LUA_REGISTRYINDEX, tname); /* get correct metatable */
> if (p == NULL || !lua_getmetatable(L, ud) || !lua_rawequal(L, -1, -2))
> p=NULL;
> lua_pop(L, 2); /* remove both metatables */
> return p;
> }
Which is what I going to do, directly in the macro that define isX()
Thanks.
--
This information is top security. When you have read it, destroy yourself.
-- Marshall McLuhan