title: How to nest modules into namespaces when registering functions from C in Lua?
body: <p>I'm trying to "nest" two modules registered from C.  I'm trying to separate the concerns a bit.</p>
  
  <p>Here's my "Core" module.  It has a single method called "setName"</p>
  
  <pre><code>int l_setName(lua_State *l)
  {
      // do something
      return 0;
  }
  
  ///////////////////////////////////////////////////////////////////////////////
  
  static luaL_Reg const core_funcs [] =
  {
      { "setName",            l_setName },
      { NULL, NULL }
  };
  
  ///////////////////////////////////////////////////////////////////////////////
  
  void l_registerFuncs( lua_State * L )
  {
      luaL_newlib(L, core_funcs);
      lua_setglobal(L, "Core");
  }
  
  ///////////////////////////////////////////////////////////////////////////////
  </code></pre>
  
  <p>From Lua, you can say <code>Core.setName("hello world")</code></p>
  
  <p>Here is a complicated subsystem with 20 functions that all have do with the same domain.</p>
  
  <pre><code>int l_importantFunction(lua_State *l)
  {
      // do something
      return 0;
  }
  
  ///////////////////////////////////////////////////////////////////////////////
  
  static luaL_Reg const subSystem_funcs [] =
  {
      { "importantFunction",          l_importantFunction },
      { NULL, NULL }
  };
  
  ///////////////////////////////////////////////////////////////////////////////
  
  void l_registerFuncs( lua_State * L )
  {
      luaL_newlib(L, subSystem_funcs);
      lua_setglobal(L, "Core.Subsystem");
  }
  
  ///////////////////////////////////////////////////////////////////////////////
  </code></pre>
  
  <p>I want this subsystem to be registered under Core.  I want to be able to say <code>Core.Subsystem.importantFunction("Hi")</code></p>
  
  <p>This won't work however. </p>
  
  <p>What is the idiomatic lua way to do this?</p>
  
  <p>After looking around at how people register "objects", it seems that this <a href="https://stackoverflow.com/questions/11100435/how-do-i-create-a-class-object-in-lua-c-api-5-2">could get very complicated</a>.</p>