How do I pass Haskell data through a C FFI as an opaque data type?
<p>I'm trying to pass some data through a C library that doesn't read or modify that data.</p>

<pre><code>foreign import ccall "lua.h lua_pushlightuserdata"
  c_lua_pushlightuserdata :: LuaState -&gt; Ptr a -&gt; IO ()

foreign import ccall "lua.h lua_touserdata"
  c_lua_touserdata :: LuaState -&gt; CInt -&gt; IO (Ptr a)

data MyData =
  MyData
  { dataIds = TVar [Int]
  , dataSomethingElse = [String]
  }

calledFromRunLuaState :: LuaState -&gt; IO ()
calledFromRunLuaState luaState = do
  dataPtr &lt;- c_lua_touserdata luaState (-1)
  myData &lt;- dataFromPtr dataPtr
  doSomethingWith myData

main = do
  luaState &lt;- Lua.newstate
  ids &lt;- atomically $ newTVar []
  c_lua_pushlightuserdata luaState (dataToPtr (MyData ids []))
  runLuaState luaState
</code></pre>

<p>I'm trying to figure out how to define <code>dataFromPtr</code> and <code>dataToPtr</code>.</p>