Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- x = {
- a = 10,
- b = 20,
- c = 30
- }
- print(x.a);
- print(x.b);
- print(x.c);
- y = {
- d = 40,
- e = 50,
- f = 60
- }
- z = {
- g = 70,
- h = 80,
- i = 90
- }
- setmetatable(z, {
- __index = function(object, key)
- if x[key] then return x[key] end
- if y[key] then return y[key] end
- return nil
- end
- })
- print(z.a); -- 10
- print(z.d); -- 40
- print(z.g); -- 70
- -- this is pretty unoptimized
- -- and it uses meta-programming
- -- which I don't require
- -- this may have errors
- -- but the gist is clear
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement