Get type of cdata object from C?

  • From: Dan Eloff <dan.eloff@xxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Sat, 20 Oct 2012 00:02:00 -0500

Hi, I've done some reading through the list and the prevailing wisdom
is that I'm probably designing things wrong if I want to access a
cdata from C.

So here's a rough overview of my architecture, feedback welcome:

-epoll server in C++, one thread per core, one lua stack per thread
-request comes in is processed by a thread and then is executed
-request execution consists of getting a lua function from an index in
a lua table (lua_rawgeti) and
then executing the function (lua_pcall) passing it one argument with a
lua_push variant
-the one result from the function is then introspected, serialized and
return to the epoll client (all in C++, since we called the function
with pcall)

It's that last step that's giving me grief. I have a nice bit of
serialization code in c++ for lua objects and tables, but I can't tell
cdata objects apart from c++ code in order to determine how to
serialize them (if I find them on the stack or in a lua table.) I can
access them with lua_topointer, but there's no real way to tell them
apart afaik.

Is there some way to do this? luajit seems to have no trouble knowing
what type a cdata is. I imagine I could copy some struct declarations
into my headers and do some evil hacking to figure it out, but I'd
like to check here first because there may be an easier way.

Thanks,
Dan

Other related posts: