Last active
December 17, 2015 05:18
-
-
Save greenrift/5556784 to your computer and use it in GitHub Desktop.
Example OOP in lua and Corona SDK
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local Blarg = {} | |
local Blarg_mt = {__index = Blarg} | |
function Blarg:new() | |
local self = {} | |
setmetatable( self, Blarg_mt ) | |
self.default = 5 | |
return self | |
end | |
function Blarg:minimum(val1, val2) | |
if(val1 < val2) then | |
return val1 | |
elseif(val1 > val2) then | |
return val2 | |
else | |
return "EQUAL" | |
end | |
end | |
function Blarg:maximum(val1, val2) | |
if(val1 > val2) then | |
return val1 | |
elseif(val1 < val2) then | |
return val2 | |
else | |
return "EQUAL" | |
end | |
end | |
function Blarg:toDefault(val) | |
if(val > self.default) then | |
return tostring(val) .. " is greater than the default" | |
elseif(val < self.default) then | |
return tostring(val) .. " is less than the default" | |
else | |
return tostring(val) .. " and the default are equal" | |
end | |
end | |
function Blarg:destroy() | |
--use this to remove memory intensive objects you create | |
--note that it is not called automagically | |
end | |
return Blarg |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment