a lot of vars rewrite
This commit is contained in:
parent
ca164ae161
commit
fabf8a7e28
|
@ -29,8 +29,18 @@ stead = {
|
|||
end
|
||||
return
|
||||
end,
|
||||
modules_ini = {},
|
||||
module_init = function(f, ...)
|
||||
if type(f) ~= 'function' then
|
||||
error ("Wrong parameter to mod_init.", 2);
|
||||
end
|
||||
stead.table.insert(stead.modules_ini, f);
|
||||
f();
|
||||
end
|
||||
}
|
||||
|
||||
module_init = stead.module_init;
|
||||
|
||||
function stead.getcmd(str)
|
||||
local a = {}
|
||||
local n = 1
|
||||
|
@ -2439,5 +2449,9 @@ stead.init = function(s)
|
|||
dsc = 'No main room defined.',
|
||||
}
|
||||
s.functions = {} -- code blocks
|
||||
local k,v
|
||||
for k,v in ipairs(s.modules_ini) do
|
||||
v();
|
||||
end
|
||||
end
|
||||
stead:init();
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
function isForSave(k, v, s) -- k - key, v - value, s -- parent table
|
||||
local i,o
|
||||
if type(s.var) == 'table' then
|
||||
for i,o in ipairs(s.var) do
|
||||
if type(s.variables) == 'table' then
|
||||
for i,o in ipairs(s.variables) do
|
||||
if o == k then
|
||||
return true
|
||||
end
|
||||
|
@ -16,15 +16,35 @@ function isForSave(k, v, s) -- k - key, v - value, s -- parent table
|
|||
return stead.string.find(k, '_') == 1
|
||||
end
|
||||
|
||||
function __vars_add(s, v)
|
||||
local k, o
|
||||
for k,o in pairs(v) do
|
||||
if tonumber(k) then
|
||||
stead.table.insert(s.variables, o);
|
||||
elseif s.variables[k] then
|
||||
error ("Variable overwrites variables object: "..tostring(k))
|
||||
elseif k ~= 'variable_type' then
|
||||
s.variables[k] = o
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function __vars_fill(v)
|
||||
local k,o
|
||||
if type(v) ~= 'table' then
|
||||
return
|
||||
end
|
||||
if type(v.var) == 'table' then
|
||||
for k,o in ipairs(v) do
|
||||
if type(o) == 'table' and o.variable_type then
|
||||
if type(v.variables) ~= 'table' then v.variables = {} end
|
||||
__vars_add(v, o);
|
||||
v[k] = nil
|
||||
end
|
||||
end
|
||||
if type(v.variables) == 'table' then
|
||||
local k,o
|
||||
local vars = {}
|
||||
for k,o in pairs(v.var) do
|
||||
for k,o in pairs(v.variables) do
|
||||
if tonumber(k) and type(o) == 'string' then
|
||||
stead.table.insert(vars, o)
|
||||
else
|
||||
|
@ -35,7 +55,7 @@ function __vars_fill(v)
|
|||
stead.table.insert(vars, k);
|
||||
end
|
||||
end
|
||||
v.var = vars;
|
||||
v.variables = vars;
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -53,3 +73,19 @@ function(f, v, ...)
|
|||
__vars_fill(v)
|
||||
return f(v, unpack(arg))
|
||||
end)
|
||||
|
||||
stead.module_init(function()
|
||||
variables = {}
|
||||
end)
|
||||
|
||||
function var(v)
|
||||
v.variable_type = true
|
||||
return v
|
||||
end
|
||||
|
||||
function global(v)
|
||||
if type(v) ~= 'table' then
|
||||
error("Wrong parameter to global.", 2);
|
||||
end
|
||||
__vars_add(_G, v);
|
||||
end
|
||||
|
|
Reference in a new issue