title: Custom constructor in Luabind
body: <p>I'm using Luabind to bind a C++ API to Lua. I have some objects that cannot be created directly, but rather must be created on another thread. I'm currently handling this by defining a "static" member called <code>create</code> that yields until the object is created:</p>
  
  <pre><code>luabind::class_&lt;Foo&gt;("Foo")
    .scope
    [
      luabind::def("create", &amp;someCreateMethod, luabind::yield)
    ]
  </code></pre>
  
  <p>This works, but has the disadvantage of complicating the client API. For these classes, you cannot create them normally (e.g. <code>local f = Foo()</code>), but instead need to do <code>local f = Foo.create()</code>.</p>
  
  <p>Is it possible to define a Luabind constructor that doesn't actually call the C++ constructor, but instead another function that returns the constructed object (and can yield in the meantime)? I've tried defining bindings for <code>__init</code> and <code>__call</code> (the latter under a <code>scope</code>, to define it on the class, not its instances), but I didn't have success with either approach.</p>