I have a global table, which, I want to keep in sync, between two different Lua states. From what I have read, and understood, the only way seems to be, in my C back-end, do a deep copy of the table between the states (if the table has been modified). Is there a better way ? Also, I saw some Lua snippets for table deep copy, but not in C, are there any libraries which do this [in C]?
P.S. I am not looking for a lua_thread
based solution (I am already using it)
P.P.S Lua Lanes seems to be close, but IMO, seems too much, because I just want to sync 1 table!
Note that __newindex won't work if the key already exists in the table you're writing to.
An alternative is to keep the table empty so that it never has any real contents. You can keep all the actual data in C, in which case neither state needs to have the table populated and your meta table can instead be used as a view onto your data from any thread. This has the bonus of not requiring a data copy on either side as the data will be available on request.
A custom __pairs function to iterate your internal data if required, plus an __index function to look at the data and you're away.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With