steed/stead/vars.lua

56 lines
1,006 B
Lua
Raw Normal View History

2010-06-25 12:31:54 +03:00
function isForSave(k, v, s) -- k - key, v - value, s -- parent table
local i,o
2010-06-18 12:04:41 +03:00
if type(s.var) == 'table' then
for i,o in ipairs(s.var) do
if o == k then
2010-06-18 12:04:41 +03:00
return true
end
end
end
2010-06-25 12:31:54 +03:00
if type(k) == 'function' then
return false
end
if type(v) == 'function' or type(v) == 'userdata' then
return false
end
return stead.string.find(k, '_') == 1
end
2010-06-18 12:04:41 +03:00
2010-06-18 12:16:07 +03:00
function __vars_fill(v)
2010-06-18 12:04:41 +03:00
local k,o
2010-06-21 20:18:30 +03:00
if type(v) ~= 'table' then
return
end
2010-06-18 12:04:41 +03:00
if type(v.var) == 'table' then
2010-06-18 12:16:07 +03:00
local k,o
local vars = {}
2010-06-18 12:04:41 +03:00
for k,o in pairs(v.var) do
if tonumber(k) and type(o) == 'string' then
stead.table.insert(vars, o)
else
2010-06-18 12:50:06 +03:00
if v[k] then
error ("Variable overwrites object property: "..tostring(k));
end
2010-06-18 12:04:41 +03:00
v[k] = o
stead.table.insert(vars, k);
end
end
v.var = vars;
end
2010-06-18 12:16:07 +03:00
end
2010-06-18 13:43:44 +03:00
vars_object = obj {
nam = 'vars',
ini = function(s)
__vars_fill(_G)
2010-06-21 20:18:30 +03:00
__vars_fill(pl)
__vars_fill(game)
2010-06-18 13:43:44 +03:00
end
}
2010-06-23 15:09:33 +03:00
obj = stead.hook(obj,
2010-06-19 20:43:55 +03:00
function(f, v, ...)
2010-06-18 12:16:07 +03:00
__vars_fill(v)
2010-06-19 20:43:55 +03:00
return f(v, unpack(arg))
2010-06-18 12:04:41 +03:00
end)