summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorjussi2024-05-09 22:05:24 +0300
committerjussi2024-05-09 22:05:24 +0300
commit1980aebdc32392f4975f6d1f8ecd9050f27e475f (patch)
treeeeeefe70368267385ea3e74c5106dd371e37985e /examples
parent02e1984781259c1f02d95ccb3bde8c533ef288a8 (diff)
downloadreilua-enhanced-1980aebdc32392f4975f6d1f8ecd9050f27e475f.tar.gz
reilua-enhanced-1980aebdc32392f4975f6d1f8ecd9050f27e475f.tar.bz2
reilua-enhanced-1980aebdc32392f4975f6d1f8ecd9050f27e475f.zip
Matrix lib clone fix.
Diffstat (limited to 'examples')
-rw-r--r--examples/resources/lib/matrix.lua33
1 files changed, 15 insertions, 18 deletions
diff --git a/examples/resources/lib/matrix.lua b/examples/resources/lib/matrix.lua
index 28d4305..1dc128f 100644
--- a/examples/resources/lib/matrix.lua
+++ b/examples/resources/lib/matrix.lua
@@ -3,23 +3,20 @@ if table.unpack == nil then
table.unpack = unpack
end
-local function deepCopy( orig )
- local copy
+local function copyMatrix( orig )
+ local copy = RL.MatrixIdentity()
- if type( orig ) == "table" then
- copy = {}
+ if orig ~= nil then
+ for y = 1, 4 do
+ for x = 1, 4 do
+ if orig[x][y] ~= nil then
+ copy[x][y] = orig[x][y]
+ end
+ end
+ end
+ end
- for origKey, origValue in next, orig, nil do
- -- If object has clone method, use that.
- copy[ deepCopy( origKey ) ] = deepCopy( origValue )
- end
-
- -- setmetatable( copy, utillib.deepCopy( getmetatable( orig ) ) )
- else -- number, string, boolean, etc.
- copy = orig
- end
-
- return copy
+ return copy
end
local Matrix = {}
@@ -50,17 +47,17 @@ Matrix.meta = {
function Matrix:new( m )
local object = setmetatable( {}, Matrix.meta )
- object.m = deepCopy( m )
+ object.m = copyMatrix( m )
return object
end
function Matrix:set( m )
- self.m = deepCopy( m )
+ self.m = copyMatrix( m )
end
function Matrix:clone()
- return Matrix:new( self )
+ return Matrix:new( self.m )
end
function Matrix:determinant()