[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Fast determination of userdata type
- From: Shaun <delius@...>
- Date: Mon, 19 Sep 2005 10:11:50 +1000 (EST)
Hi Guys,
Just wondering if there is any collected wisdom about the fastest/nicest
way of determining the type of userdata passed into a C function (from
LUA).
For example, assuming I have a function that can accept three different
types of userdata (which are actually C++ objects), how do you generally
go about determining which of the three types it is efficiently?
The most obvious idea seems to be:
if (!lua_getmetatable(L, object))
return(NULL);
luaL_getmetatable(L, "Class");
int ok = lua_rawequal(L, -1, -2);
lua_pop(L, 2);
if (!ok)
return(NULL);
Not exactly fast. I'm thinking some sort of shim that adds a class
identifier to the start of the userdata would be much faster but will make
my implementation a pain. Any other ideas?
Cheers,
Shaun