title: Calling C nested function pointer from Lua
body: <p>I have the following C struct, that contains function pointer:</p>
  
  <pre><code>struct db {
      struct db_impl *impl;
      void (*test)(struct db *self); // How to invoke it from Lua??
  };
  void (*db_test)(void); // this I can invoke from Lua
  
  struct db * get_db() {
      // create and init db
      struct db * db = init ...
      db-&gt;test = &amp;db_real_impl; // db_real_impl is some C function
      return db;
  }
  </code></pre>
  
  <p>So the test function pointer after initialization points to some function.
  Now I need to call that function from Lua using FFI library, but it fails with error: <code>'void' is not callable</code>.</p>
  
  <pre><code>local db = ffi.C.get_db()
  db.test(db)  -- fails to invoke
  -- Error message: 'void' is not callable
  
  ffi.C.db_test()  -- this works fine
  </code></pre>
  
  <p>In C the code would be:</p>
  
  <pre><code>struct db *db = get_db();
  db-&gt;test(db);
  </code></pre>
  
  <p>In Lua I'm able to invoke free function pointers easily, but can't invoke function pointer from struct. How to invoke it from Lua?</p>