summaryrefslogtreecommitdiff
path: root/Obj.lua
diff options
context:
space:
mode:
authorthe lemons <citrons@mondecitronne.com>2022-08-21 20:37:53 -0500
committerthe lemons <citrons@mondecitronne.com>2022-08-21 20:37:53 -0500
commit4fbbf73aeb39566f73d54e3d42670c7c258e2466 (patch)
tree41bef03c3547c69b8e703b068da4d84c8df1ce31 /Obj.lua
everything so far
basic mechanics and player control have been implemented, but they work very poorly at present.
Diffstat (limited to 'Obj.lua')
-rw-r--r--Obj.lua68
1 files changed, 68 insertions, 0 deletions
diff --git a/Obj.lua b/Obj.lua
new file mode 100644
index 0000000..cbd6f81
--- /dev/null
+++ b/Obj.lua
@@ -0,0 +1,68 @@
+--
+-- classic
+--
+-- Copyright (c) 2014, rxi
+--
+-- This module is free software; you can redistribute it and/or modify it under
+-- the terms of the MIT license. See LICENSE for details.
+--
+
+
+local Object = {}
+Object.__index = Object
+
+
+function Object:new()
+end
+
+
+function Object:extend()
+ local cls = {}
+ for k, v in pairs(self) do
+ if k:find("__") == 1 then
+ cls[k] = v
+ end
+ end
+ cls.__index = cls
+ cls.super = self
+ setmetatable(cls, self)
+ return cls
+end
+
+
+function Object:implement(...)
+ for _, cls in pairs({...}) do
+ for k, v in pairs(cls) do
+ if self[k] == nil and type(v) == "function" then
+ self[k] = v
+ end
+ end
+ end
+end
+
+
+function Object:is(T)
+ local mt = getmetatable(self)
+ while mt do
+ if mt == T then
+ return true
+ end
+ mt = getmetatable(mt)
+ end
+ return false
+end
+
+
+function Object:__tostring()
+ return "Object"
+end
+
+
+function Object:__call(...)
+ local obj = setmetatable({}, self)
+ obj:new(...)
+ return obj
+end
+
+
+return Object