'How to associate a newly allocated C structure to a lua created object and automatically free it when the lua object is closed/GC-ed
Say I have a lua object created with io.open/io.popen. is there a way to bind a C structure to it by calling some c defined function from lua that takes the (io.open/io.popen)-ed object as an argument and binds a newly allocated struct to it? the purpose of wanting to do this is so I can hopefully keep that newly allocated structure around until the lua object gets closed or garbage collected and have that free the C structure automatically at that point. I've been reading on metamethods but I'm not sure I want to overwrite the default object behavior (maybe just add an extra function?) or if that's even the right approach to achieve the above. Any help/hint on how to achieve this would be greatly appreciated!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
