ClassDB is now in C++
This commit is contained in:
@@ -1,42 +0,0 @@
|
||||
|
||||
classdb = table.coerce(classdb)
|
||||
|
||||
-- classdb.create: creates a new class database.
|
||||
function classdb.create()
|
||||
return {}
|
||||
end
|
||||
|
||||
-- Given a class database, removes all the functions that have
|
||||
-- been inserted into it, but keeps the class and action tables.
|
||||
function classdb.reset(db)
|
||||
for name,maybeclass in pairs(db) do
|
||||
local class = table.coerce(maybeclass)
|
||||
local action = table.coerce(rawget(class, "action"))
|
||||
table.rawclear(class)
|
||||
table.rawclear(action)
|
||||
rawset(db, name, class)
|
||||
class.action = action
|
||||
class.__index = class
|
||||
class.__class = name
|
||||
end
|
||||
end
|
||||
|
||||
-- Given a class_db, makes an accessor that fetches classes
|
||||
-- from that class db.
|
||||
function classdb.accessor(db)
|
||||
return function(name)
|
||||
local class = rawget(db, name)
|
||||
if type(class) ~= "table" then
|
||||
class = {}
|
||||
rawset(db, name, class)
|
||||
class.action = {}
|
||||
class.__index = class
|
||||
class.__class = name
|
||||
end
|
||||
return class
|
||||
end
|
||||
end
|
||||
|
||||
-- Make a global class database to use for the super.
|
||||
classdb.database = {}
|
||||
class = classdb.accessor(classdb.database)
|
||||
@@ -3,8 +3,6 @@
|
||||
# in the order that they're supposed to be loaded.
|
||||
#
|
||||
|
||||
tableutil.lua
|
||||
classdb.lua
|
||||
inspect.lua
|
||||
main.lua
|
||||
|
||||
|
||||
@@ -331,5 +331,5 @@ function inspect.inspect(root, options)
|
||||
return table.concat(inspector.buffer)
|
||||
end
|
||||
|
||||
setmetatable(inspect, { __call = function(_, ...) return inspect.inspect(...) end })
|
||||
_G.inspect = inspect.inspect
|
||||
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
|
||||
-- Coerce T to be a table.
|
||||
-- If T is a table, return it. If not, return a blank table.
|
||||
function table.coerce(t)
|
||||
if type(t) == "table" then
|
||||
return t
|
||||
else
|
||||
return {}
|
||||
end
|
||||
end
|
||||
|
||||
-- Clear the table out. Deletes all keys, removes any metatable.
|
||||
-- TODO: this doesn't work on tables that have __metatable metamethod.
|
||||
function table.rawclear(t)
|
||||
for k in pairs(t) do
|
||||
rawset(t, k, nil)
|
||||
end
|
||||
setmetatable(t, nil)
|
||||
return t
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user