Re: Accessing FFI cdata from the Lua C API

  • From: Florian Weimer <fw@xxxxxxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Mon, 16 Jul 2012 18:50:31 +0200

* Mike Pall:

> static void *luaL_checkcdata(lua_State *L, int narg)
> {
>   if (lua_type(L, narg) != 10)
>     luaL_typerror(L, narg, "cdata");
>   return lua_topointer(L, narg);
> }
>
> const char *buffer = *(const char **)luaL_checkcdata(L, 2);

Thanks, this is much better.

(I'm a bit surprised that the addresses of cdata boxes are exposed
directly; this restricts GC options somewhat.  Without that, the boxes
could use a compacting GC.)

> Whether the size_t ends up as a cdata object depends on how it's
> generated and whether it's a 32 bit or 64 bit type.

It's going to be a number on the lua side anyway, so no real problem
there.

Other related posts: