Jump to content

metatables


karlis

Recommended Posts

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...