-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathObject.lua
More file actions
36 lines (28 loc) · 808 Bytes
/
Object.lua
File metadata and controls
36 lines (28 loc) · 808 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
--- Base class for all other classes.
--
-- Could have used Giant's Class() but then we'd always need to run
-- from the game. This works in standalone mode too.
--
function cgClass( members, baseClass )
members = members or {}
local mt = {
__metatable = members;
__index = members;
}
if baseClass ~= nil then
setmetatable( members, { __index = baseClass } );
end;
local function new(self, init)
return setmetatable(init or {}, mt);
end;
local function copy(self, ...)
local newobj = self:new(unpack(arg));
for n,v in pairs(self) do
newobj[n] = v;
end;
return newobj;
end;
members.new = members.new or new;
members.copy = members.copy or copy;
return mt;
end;