Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local annotation = function() end
- local isClass = function(t)
- if type(t) ~= "table" then return false end
- if not getmetatable(t) then return false end
- if getmetatable(t).__type == "class" then return true end
- return false
- end
- local parseannotations = function(left,right)
- if type(left) == "table" and rawget(left,"__type") == "annotation" and type(right) == "table" and rawget(right,"__type") == "annotation" then
- local ann = annotation()
- right.copyto(ann)
- left.copyto(ann)
- return ann
- elseif (isClass(left)) or (isClass(right)) then
- if isClass(left) then
- if type(right) == "table" and rawget(right,"__type") == "annotation" then
- local a = annotation("object")
- right.copyto(a)
- a.objType = getmetatable(left).__class.name
- return a
- else
- local a = annotation("object")
- a.objType = getmetatable(left).__class.name
- a.setValue(right)
- return a
- end
- elseif isClass(right) then
- local a = annotation("object")
- left.copyto(a)
- a.objType = getmetatable(right).__class.name
- return a
- end
- elseif rawget(left,"__type") == "annotation" and (not (type(right) == "table" and (rawget(right,"__type") == "annotation" or rawget(right,"__type") == "annotation"))) then
- local ann = annotation()
- ann.setValue(right)
- left.copyto(ann)
- ann.objType = left.objType
- return ann
- end
- end
- annotation = function(desc)
- local ann = {}
- ann.__type = "annotation"
- ann.value = nil
- ann.type = _type
- ann.descriptors = {[1] = desc}
- ann.objType = nil
- ann.get = function() return ann.descriptors end
- ann.copyto = function(next)
- for i=1,#ann.descriptors do
- table.insert(next.descriptors,ann.descriptors[i])
- end
- next.objType = ann.objType
- end
- ann.setValue = function(val)
- ann.value = val
- ann.type = (type(val) == "function" and "method") or "attribute"
- end
- return setmetatable(ann,{
- __sub = parseannotations
- })
- end
- return annotation, parseannotations
Advertisement
Add Comment
Please, Sign In to add comment