Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
anshve
/
PongGame
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
26c8e3d1
authored
Apr 28, 2022
by
anshve
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
d2211268
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
95 additions
and
0 deletions
PongSource/lib/class.lua
PongSource/lib/class.lua
0 → 100644
View file @
26c8e3d1
--[[
Copyright (c) 2010-2013 Matthias Richter
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
Except as contained in this notice, the name(s) of the above copyright holders
shall not be used in advertising or otherwise to promote the sale, use or
other dealings in this Software without prior written authorization.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
]]
--
local
function
include_helper
(
to
,
from
,
seen
)
if
from
==
nil
then
return
to
elseif
type
(
from
)
~=
'table'
then
return
from
elseif
seen
[
from
]
then
return
seen
[
from
]
end
seen
[
from
]
=
to
for
k
,
v
in
pairs
(
from
)
do
k
=
include_helper
({},
k
,
seen
)
-- keys might also be tables
if
to
[
k
]
==
nil
then
to
[
k
]
=
include_helper
({},
v
,
seen
)
end
end
return
to
end
-- deeply copies `other' into `class'. keys in `other' that are already
-- defined in `class' are omitted
local
function
include
(
class
,
other
)
return
include_helper
(
class
,
other
,
{})
end
-- returns a deep copy of `other'
local
function
clone
(
other
)
return
setmetatable
(
include
({},
other
),
getmetatable
(
other
))
end
local
function
new
(
class
)
-- mixins
class
=
class
or
{}
-- class can be nil
local
inc
=
class
.
__includes
or
{}
if
getmetatable
(
inc
)
then
inc
=
{
inc
}
end
for
_
,
other
in
ipairs
(
inc
)
do
if
type
(
other
)
==
"string"
then
other
=
_G
[
other
]
end
include
(
class
,
other
)
end
-- class implementation
class
.
__index
=
class
class
.
init
=
class
.
init
or
class
[
1
]
or
function
()
end
class
.
include
=
class
.
include
or
include
class
.
clone
=
class
.
clone
or
clone
-- constructor call
return
setmetatable
(
class
,
{
__call
=
function
(
c
,
...
)
local
o
=
setmetatable
({},
c
)
o
:
init
(
...
)
return
o
end
})
end
-- interface for cross class-system compatibility (see https://github.com/bartbes/Class-Commons).
if
class_commons
~=
false
and
not
common
then
common
=
{}
function
common
.
class
(
name
,
prototype
,
parent
)
return
new
{
__includes
=
{
prototype
,
parent
}}
end
function
common
.
instance
(
class
,
...
)
return
class
(
...
)
end
end
-- the module
return
setmetatable
({
new
=
new
,
include
=
include
,
clone
=
clone
},
{
__call
=
function
(
_
,
...
)
return
new
(
...
)
end
})
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment