Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- _VARS = class()
- _VARS.storage = {}
- function _VARS:reg(var)
- assert(is_a(var, _VAR), "Cannot register variable because wrong class was provided.")
- self.storage[var.name] = var
- self:__defineGetter(var.name, function (self, var) return var.curv end, var)
- self:__defineSetter(var.name, function (self, var, val)
- if var:isInReach(val) then
- local oval = var.curv
- var.curv = val
- if var.chng and type(var.chng) == "function" then
- var:chng(oval, val)
- end
- end
- end, var)
- end
- function _VARS:r(vtype, name, ...)
- self:reg(_G[vtype](name, ...))
- end
- EV = _VARS()
- _VAR = class()
- function _VAR:__init(name, minv, curv, maxv, persist, onchange)
- assert(name, "Cannot register variable: name is missing.")
- assert(curv, "Cannot register variable: no value set.")
- self.name = name
- self.minv = minv
- self.maxv = maxv
- self.curv = curv
- self.pers = persist
- self.chng = onchange
- end
- IVAR = class(_VAR)
- function IVAR:__tostring() return "IVAR" end
- function IVAR:__init(name, minv, curv, maxv)
- assert(type(minv) == "number" and type(curv) == "number" and type(maxv) == "number", "Wrong value type provided to IVAR.")
- self[_VAR].__user_init(self, name, minv, curv, maxv, false, nil)
- end
- function IVAR:isInReach(v)
- if type(v) ~= "number" then
- log(ERROR, "Wrong value type passed to variable.")
- end
- if v < self.minv or v > self.maxv then
- log(ERROR, "Variable accepts only values of range " .. self.minv .. " to " .. self.maxv)
- return false
- end
- return true
- end
- IVARP = class(IVAR)
- function IVARP:__tostring() return "IVARP" end
- function IVARP:__init(name, minv, curv, maxv)
- assert(type(minv) == "number" and type(curv) == "number" and type(maxv) == "number", "Wrong value type provided to IVARP.")
- self[_VAR].__user_init(self, name, minv, curv, maxv, true, nil)
- end
- IVARF = class(IVAR)
- function IVARF:__tostring() return "IVARF" end
- function IVARF:__init(name, minv, curv, maxv, onchange)
- assert(type(minv) == "number" and type(curv) == "number" and type(maxv) == "number", "Wrong value type provided to IVARF.")
- assert(onchange and type(onchange) == "function", "Wrong type of onchange callback to IVARF.")
- self[_VAR].__user_init(self, name, minv, curv, maxv, false, onchange)
- end
- IVARFP = class(IVARF)
- function IVARFP:__tostring() return "IVARFP" end
- function IVARFP:__init(name, minv, curv, maxv, onchange)
- assert(type(minv) == "number" and type(curv) == "number" and type(maxv) == "number", "Wrong value type provided to IVARFP.")
- assert(onchange and type(onchange) == "function", "Wrong type of onchange callback to IVARFP.")
- self[_VAR].__user_init(self, name, minv, curv, maxv, true, onchange)
- end
- FVAR = class(IVAR)
- function FVAR:__tostring() return "FVAR" end
- FVARP = class(IVARP)
- function FVARP:__tostring() return "FVARP" end
- FVARF = class(IVARF)
- function FVARF:__tostring() return "FVARF" end
- FVARFP = class(IVARFP)
- function FVARFP:__tostring() return "FVARFP" end
- SVAR = class(_VAR)
- function SVAR:__tostring() return "SVAR" end
- function SVAR:__init(name, curv)
- assert(type(curv) == "string", "Wrong value type provided to SVAR.")
- self[_VAR].__user_init(self, name, nil, curv, nil, false, nil)
- end
- function SVAR:isInReach(v)
- if type(v) ~= "string" then
- log(ERROR, "Wrong value type passed to variable.")
- return false
- end
- return true
- end
- SVARP = class(SVAR)
- function SVARP:__tostring() return "SVARP" end
- function SVARP:__init(name, curv)
- assert(type(curv) == "string", "Wrong value type provided to SVARP.")
- self[_VAR].__user_init(self, name, nil, curv, nil, true, nil)
- end
- SVARF = class(SVAR)
- function SVARF:__tostring() return "SVARF" end
- function SVARF:__init(name, curv, onchange)
- assert(type(curv) == "string", "Wrong value type provided to SVARF.")
- assert(onchange and type(onchange) == "function", "Wrong type of onchange callback to SVARF.")
- self[_VAR].__user_init(self, name, nil, curv, nil, false, onchange)
- end
- SVARFP = class(SVARF)
- function SVARFP:__tostring() return "SVARFP" end
- function SVARFP:__init(name, curv, onchange)
- assert(type(curv) == "string", "Wrong value type provided to SVARFP.")
- assert(onchange and type(onchange) == "function", "Wrong type of onchange callback to SVARFP.")
- self[_VAR].__user_init(self, name, nil, curv, nil, true, onchange)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement