Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- just messing with oop pribbly a mega fail
- by BigSHinyToys
- ]]--
- local function class(tPrivate,tFunctions)
- local tClass = tFunctions
- local mt = {
- __index = tClass
- }
- tClass.new = function()
- local tObj = {}
- for key,value in pairs(tPrivate) do
- tObj[key] = value
- end
- setmetatable(tObj,mt)
- return tObj
- end
- return tClass
- end
- local counter = class(
- {
- value = 0,
- },
- {
- get = function(self)
- return self.value
- end,
- set = function(self,input)
- self.value = input and tonumber(input) or error("Unexpected input type : "..type(input))
- end,
- inc = function(self)
- self.value = self.value + 1
- end,
- dec = function(self)
- self.value = self.value - 1
- end,
- reset = function(self)
- self.value = 0
- end
- }
- )
- local count = counter.new()
- while true do
- term.setCursorPos(1,1)
- print(count:get())
- local event = {os.pullEvent()}
- if event[1] == "key" then
- if event[2] == 200 then -- up key
- count:inc()
- elseif event[2] == 208 then -- down key
- count:dec()
- elseif event[2] == 14 then
- break
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement