Using Nick's serializer in http://www.gammon.com.au/forum/bbshowpost.php?bbsubject_id=4960 I've been able to save some tables into MUSHclient variables, which is all good and dandy. However, now I want to stick some metamethods on those tables and it just wont work. I haven't got much experience with metatables, besides getting it to work, so I figure there's something I'm missing here.
Currently I have this variable (skoid_cfg) saved with the serializer.
The "skoid_cfg" variable is loaded with the following code.
Now I want to attach two metamethods to this table. They look like this.
But lo and behold! No matter where I put the "setmetatable", it wont work.. I tried defining the cfg table before loading it, and setting the metatable right after. But I figure it's all overwritten when loading it (since it's redefined). But since setting the metatable after loading the table wont work neither, I'm out of ideas..
Anyone?
Currently I have this variable (skoid_cfg) saved with the serializer.
cfg = {}
cfg["cure_salve"] = true
cfg["heal_mana"] = true
cfg["heal_mana_offset"] = 15
cfg.loot = true
cfg.timer = trueThe "skoid_cfg" variable is loaded with the following code.
if GetVariable("skoid_cfg") then loadstring(GetVariable("skoid_cfg"))() endNow I want to attach two metamethods to this table. They look like this.
skoid_mt = { __index = function (t, name) gui_update() end; __newindex = function (t, name, val) gui_update end; }
setmetatable(cfg, skoid_mt)But lo and behold! No matter where I put the "setmetatable", it wont work.. I tried defining the cfg table before loading it, and setting the metatable right after. But I figure it's all overwritten when loading it (since it's redefined). But since setting the metatable after loading the table wont work neither, I'm out of ideas..
Anyone?