I have a table that contains many different classes. I would like to use these classes directly from the module that connects this table without referring to parents ( Window instead of app.gui.Window ).
Here is the simplest example of what I need:
t = { a = 1, b = 2, c = 3 } function f(t) print(tb) -- так работает print(b) -- как заставить работать так? end f(t) UPD: Of course, the easiest way would be to solve the problem in the following way: b = tb , but let's agree that I don’t know the names of the keys from the table t in advance (more precisely, they certainly are known to me, but a = ta; b = tb; c = tc ... z = tz - this is some kind of govnokod).
Here is a solution that just occurred to me:
function f(t) print(tb) -- так работает for k, v in pairs(t) do _G[k] = v end print(b) -- и так работает! end ... But, as you see, it affects the global scope, not the local one, and this is unacceptable! I need a local analogue of _G , some _L .
There is an idea to create such a variable and register in its metamethods debug.getlocal and debug.setlocal , although I haven’t really figured out the syntax of these functions and in metamethods it is not yet strong, but I will try.
local Window=app.gui.Windowand then useWindowor even withoutlocal- Mike V.