I know there are examples of creating pointers using the LuaJIT FFI, but most of these aren\'t pointed to existing data. One such example of this is here: How to pass a poin
I was able to do that with a C function that copies the cdata pointer like this
void cdataToPointer(void *cdata, void **pointer) {
*pointer = cdata;
}
// ...
void *mycdata = NULL;
lua_pushlightuserdata(L, &mycdata);
lua_setglobal(L, "__TEMP_USERDATA__");
luaL_dostring(L,
"local ffi = require'ffi'\n"
"ffi.cdef[[\n"
" void cdataToPointer(void *cdata, void **pointer);\n"
"]]\n"
"ffi.C.cdataToPointer(mycdata, __TEMP_USERDATA__)\n");