lua-users home
lua-l archive

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


I don't think I made myself clear. What happens is that the function in C++ that is called from lua can receive different types of userdata. When I do luaL_checkudata I have to say what kind of userdata I'm going to read. What I want to do is to check what kind of userdata was sent from Lua.

thanks,
Zé Pedro

On 2/2/07, Rici Lake <lua@ricilake.net> wrote:

On 2-Feb-07, at 12:20 PM, Zé Pedro wrote:

> Sorry I've sent the message unfinished...
>
> Hi, I have a method in C++ accessible from Lua that receives an
> userdata object as a parameter. But it can receive one of several
> userdata types.If I could get the string that I used when the
> metatable was created (luaL_newmetatable(pLuaState, " Zara.sound");) I
> could compare it, but I can't find a way to do it.

At the risk of being obvious:

int my_newmetatable (lua_State *L, const char *tname) {
   int rc = luaL_newmetatable(L, tname);
   if (rc) {
     lua_pushstring(L, tname);
     lua_setfield(L, -2, "__typename");
   }
   return rc;
}




--
Believe nothing, no matter where you read it, or who said it,
no matter if I have said it, unless it agrees with your own reason
and your common sense.
- Buda

Para quê ter olhos azuis, se a Natureza deixa os meus  vermelhos?
- Bob Marley

"Don't try to use what you learn from Buddhism to be a Buddhist;
use it to be a better whatever-you-already-are."
- His Holiness the 14th Dalai Lama

Idealism is what precedes experience; cynicism is what follows.
  - David T. Wolf

"Please don't download, because I want to get a pool in my second home."
  - Kanye West