In some place of the code, I use my variable to reference the table (that is, its identity):

local defines = ffi.lcpp_defs 

However, the library each time creates a new table with the same name. In turn, the local defines still refers to the old table (identity). How to make a link to the name of the table?

    2 answers 2

    In lua, you can use the so-called. "proxy table", forward all (necessary) table methods using metamethods. For example:

     local defines = setmetatable({}, { __index = function(s, i) return ffi.lcpp_def[i] end}) 

    In this example, we can only read data from a table.

    PS: this technique is also used when necessary limited access to the table (in combination with upvalue).

      You can use the metamethods __newindex and __index:

       -- Проксификатор function proxytable(table,key) return setmetatable({},{ __index=function(self,k) return table[key][k] end, __newindex=function(self,k,v) table[key][k] = v end, }) end local defines = proxytable(ffi,"lcpp_defs") 

      In this example, you can both read and write to the table referenced by the proxy table.