lua-users home
lua-l archive

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


On 2/25/06, Torsten Karwoth <agonizer@t-online.de> wrote:
> > For example, luaL_checkudata() used to return NULL if the type didn't
> > match but in 5.1 it seems to trigger an error, which is not what I want
> > because I just want to check the type not kill the runtime (ie. 5.0
> > behaviour seemed better).
>
> No, this behaviour is right (now):
>
> all luaL_check(..) triggers an error (also in lua 5.0), i.e.
> luaL_checkstring, luaL_checknumber etc. so its good to know that
> luaL_checkudata does the same for now. This means, i can change
> the code
>
>         aUser **UP = luaL_checkudata(L, idx, "User");
>         if (!UP)
>                 luaL_typerror(L, idx, "User");
>         return(UP);
>
> to a simple
>
>         aUser **UP = luaL_checkudata(L, idx, "User");
>
> or am i wrong?

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.

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.  :-(

--
This information is top security. When you have read it, destroy yourself.
-- Marshall McLuhan