The very first step is to make a table which will hold ALL of your game objects, or if you wish to separate your game objects into different spaces (or game spaces) then a table what holds all of your game spaces, which are tables which hold all of your game objects.
Where to store your lua components
Now we should talk about what we want to store inside of a lua component.
You may have noticed that some of the data stored inside of the component could be accessed from the game object however this is one of those things where just storing that data inside of the component itself is much simpler when working with the component since it means that you have to type less to get something like the owning game space or the handle to the owning C++ game object.
Each lua component has a C++ counterpart
So far we have only setup a way for lua to know about what lua components are attached onto a game object and we've left C++ blind to this. We could make a function that queries the component list and returns it back to C++ however that would be cumbersome to call every time we need that information, instead I purpose that for each lua component a game object has we have a corresponding instance of a "lua component proxy" component inside of C++. I apologize for how wordy this is going to get.
The "lua component proxy" component in it's simplest form is just a string with the name of the real lua component attached to the game object. You could actually make this a vector of strings inside of your game object if you really wanted to however there may be some additional functionality you'll want to add (like lua component serialization) so that might not be the best of ideas. It should also act just like any C++ components that you have (an exception here is if you have a limit of one component per type on each object then you're going to want to store the "lua component proxy" components differently.)
Beyond simply storing the name of the lua component, the "lua component proxy" component should also call the proper lua functions to instantiate and attach the lua component onto the game object, as well as call the proper lua function to remove the lua component when the "lua component proxy" component is removed from the game object (or the game object is being deleted.) Most importantly however is all of the "lua component proxy" components should be serialized so that when a saved game object is loaded it will have all the proper lua component attached to it.
The actual functions
--[[ Registers a game space inside of lua. name is the name of the gamespace and space is a pointer to the game space. We will want to store the pointer inside of the lua table. ]]--
--[[ Removes a game space which will delete all objects and lua components inside of it ]]--
--[[ Attaches a lua component onto a game object, if this is the first lua component attached to the game object then we will make a new game object table inside of the game space. space is the name of the game space,owner is the handle or identifier to the owning game object, compHandle is the handle or identifier to the "lua component" component, compName is the name of the component ]]--
AttachComponentToObject(space, owner, compHandle, compName)
--[[ Removes a lua component from a game object. space is the name of the game space, objHandle is the handle of the owning object, and compHandle is the handle to the "lua component" component. ]]--
RemoveComponentFromObject(space, objHandle, compHandle)
In my implementation the Attach/Remove component functions are only ever called by my "lua component proxy" component.
Updating lua components
Bonus Features on your lua component proxy
We introduce some arbitrary limits with this code snippet, first off we never serialize a variable if it's a table or userdata. By writing a recursive function it's actually very simple to save tables as well so you can implement that yourself if you please. The next limitation is that no variables with a leading underscore "_" are serialized. This is chosen so that I can easily hide variables from being serialized, completely optional mind you.
This is a shotgun approach to serializing lua components and is purely a proof of concept so I wouldn't recommend implementing this verbosely but instead a modified version that better suits your needs. Below is the very complicated script for Deserializing a lua component.