Here is the way I approached this problem:
- Create a wrapper class around C++ luabridge class (If you have
class Display.A()
in C++, create classA()
in Lua) - Store a weak table inside that wrapper class (
self.WeakTable={}
andsetmetatable(self.WeakTable, { __mode = 'k' })
) - In the weak table, reference self: (
self.WeakTable.self=self
) - Pass
self.WeakTable
to C++ and store in asLuaRef
- this will gc Create a wrapper function like so:
Container:On(EventType.Add,function(WeakTableParams) WeakTableParams.self.Callback(); end)