180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
|
end
fn.proto = function(tbl,proto)
local meta = getmetatable(tbl)
local nm = {__index = proto or tbl}
if meta ~= nil then
nm = table.copy(meta)
nm[__index] = proto
nm[__metatable] = meta
end
return setmetatable(tbl or {},nm)
end
fn.case = function(e, c)
if type(c[e]) == 'function'
then return (c[e])(e)
else return c[e]
end
|
|
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
|
end
fn.proto = function(tbl,proto)
local meta = getmetatable(tbl)
local nm = {__index = proto or tbl}
if meta ~= nil then
nm = table.copy(meta)
nm.__index = proto
nm.__metatable = meta
end
return setmetatable(tbl or {},nm)
end
fn.defaults = function(dft, tbl)
tbl = tbl or {}
local rp = {}
for k,v in pairs(dft) do
if tbl[k] == nil then rp[k] = v end
end
return fn.proto(rp, tbl)
end
fn.case = function(e, c)
if type(c[e]) == 'function'
then return (c[e])(e)
else return c[e]
end
|