karlis Posted October 27, 2011 Share Posted October 27, 2011 hey there, i just tried to use metatables for the first time, and i failed. it just doesn't call the __newindex function. what i want to do is when settings table is changed also global variable is changed, but it doesn't work. .. settings=getSettings() --that is valid table setmetatable(settings,{ __newindex=function(_,key,value) _G[key]=value end }) .. PS:yes, i know it would be better just calling the tables, but as code already have some of the variables called 150times, and its a long mess already, i don't want to do that just to save KB or two. Link to comment
karlis Posted October 27, 2011 Author Share Posted October 27, 2011 __index is called when you get variable, __newindex, when you set it. Link to comment
Orange Posted October 27, 2011 Share Posted October 27, 2011 I don't see any point of using metatables here. Can you explain "why"? Link to comment
karlis Posted October 27, 2011 Author Share Posted October 27, 2011 i need to use tables to get current, backuped(in case of cancelation), default and probably server override options. but now i think i figured to just use default value table as refference what to take from _G for current settings, therefore leaving no need for this. still i'd like to know what i did wrong so next time i can do it. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now