summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAki <nthirtyone@gmail.com>2017-07-05 17:00:07 +0200
committerAki <nthirtyone@gmail.com>2017-07-05 17:00:07 +0200
commitf525f386952506f7c14e241d087b7473f230235b (patch)
tree827d1f3fa721a70b862891a73f0801ac6ae897f9
parentb5c3f635128845baa6fdc738df44c5fe88b3db82 (diff)
downloadroflnauts-f525f386952506f7c14e241d087b7473f230235b.zip
roflnauts-f525f386952506f7c14e241d087b7473f230235b.tar.gz
roflnauts-f525f386952506f7c14e241d087b7473f230235b.tar.bz2
Object lib added as git submodule
-rw-r--r--.gitmodules3
-rw-r--r--lib/Object.lua77
m---------lib/object0
-rw-r--r--not/Object.lua2
4 files changed, 4 insertions, 78 deletions
diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 0000000..2388b92
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,3 @@
+[submodule "lib/object"]
+ path = lib/object
+ url = https://github.com/nthirtyone/object.git
diff --git a/lib/Object.lua b/lib/Object.lua
deleted file mode 100644
index b241bb2..0000000
--- a/lib/Object.lua
+++ /dev/null
@@ -1,77 +0,0 @@
---- You may not believe me but we are not returning this one.
--- This table is used as metatable for classes e.g. for `Object`.
-local Class = {}
-
---- Metamethod for classes.
--- Creates new instance of class calling `new()` method (constructor) with all parameters passed.
-Class.__call = function (self, ...)
- local o = setmetatable({}, self)
- self.new(o, ...)
- return o
-end
-
---- Metamethod for classes.
--- First checks if `__index` (instance prototype) have field we are looking for. Then it tries to find it in super class.
-Class.__index = function (self, key)
- if rawget(self, "__index") ~= nil then
- if rawget(self, "__index")[key] ~= nil then
- return rawget(self, "__index")[key]
- end
- end
- if rawget(self, "__super") ~= nil then
- if rawget(self, "__super")[key] ~= nil then
- return rawget(self, "__super")[key]
- end
- end
- return nil
-end
---- Metamethod for classes.
--- Redirects creating new properties to class'es `__index` which is used as a prototype for instances of class.
--- Only `new` method and metamethods are allowed to be written to class'es table directly.
-Class.__newindex = function(self, key, value)
- if key == "new" or key:sub(1, 2) == "__" then
- rawset(self, key, value)
- else
- self.__index[key] = value
- end
-end
-
---- Creates new class from parent class.
--- New class will call parent's constructor unless new constructor will be defined.
--- @param parent super class of new class
-local extends = function (parent)
- local self = setmetatable({}, Class)
- rawset(self, "__index", {})
- if parent then
- setmetatable(self.__index, {__index = parent.__index})
- end
- rawset(self, "__super", parent)
- return self
-end
-
---- Almost empty class.
--- Used to create new classes via `extend()` method:
--- `Child = Object:extend()`
--- Contains `is()` and `new()` methods. Later one isn't available from inside of instances.
-local Object = extends(nil)
-rawset(Object, "extends", extends)
-Object.new = function (self) end
-
---- Checks if class or instance of class is a child of class passed through parameter.
--- @param class table we want to test against (preferably class table)
--- @return boolean which is false if tested sample is not child of passed class
-function Object:is (class)
- if not class then return false end
- if self == class or getmetatable(self) == class then
- return true
- end
- if self.__super then
- return self.__super:is(class)
- end
- if getmetatable(self).__super then
- return getmetatable(self).__super:is(class)
- end
- return false
-end
-
-return Object
diff --git a/lib/object b/lib/object
new file mode 160000
+Subproject eacf0f60c0752616407fbca6cd9d8ca9757ce62
diff --git a/not/Object.lua b/not/Object.lua
index fbc41e5..30b91b5 100644
--- a/not/Object.lua
+++ b/not/Object.lua
@@ -1,3 +1,3 @@
-- Wrapping library to game's hierarchy in a shameless way.
-Object = require "lib.Object"
+Object = require "lib.object.Object"
return Object