lua-users home
lua-l archive

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


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.
Consider the following example:

int LObject::setRepresentation(lua_State* pLuaState)
{
    try
    {
        //In here I'm trying to get the field were the userdata type is set (I thought that this could be a way to do it)
        cout << "--------------------------------" << endl;
        cout << lua_objlen(pLuaState,1) << endl;    //It returns 4 so I thought one of the positions would be the type
        cout << "-" << endl;
        lua_rawgeti(pLuaState,1,1);    //in what position is it?
       
cout << type = lua_tostring(pLuaState,-1) << endl;
        cout << "--------------------------------" << endl;
           
        Representation* rep = static_cast<ZMaterial*>(luaL_checkudata(pLuaState,3,"Zara.representation"));     //

--
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