script.src
Utils = {} Utils.is_class = function(obj) return typeof(obj) == "map" and obj.hasIndex("__isa") end function Utils.attr_to_s = function(value) if value == null then return "null" if Utils.is_class(value) then return value.inspect if typeof(value) == "list" then return value.inspect if typeof(value) == "string" then return "'" + value + "'" return value end function list.inspect = function(attrs_overwrite = null) l = self[0:] for i in l.indexes if attrs_overwrite then if Utils.is_class(l[i]) then l[i] = l[i].inspect(attrs_overwrite) if typeof(l[i]) == "list" then l[i] = l[i].inspect(attrs_overwrite) else if Utils.is_class(l[i]) then l[i] = l[i].inspect if typeof(l[i]) == "list" then l[i] = l[i].inspect end if end for return "[" + l.join(", ") + "]" end function map.inspect = function(attrs_overwrite = null) if self.hasIndex("__isa") then class_name = "NotFound" for i in globals.indexes if self isa globals[i] then class_name = i end for attrs_inspect = [] attrs = null if self["__isa"].hasIndex("attrs") then attrs = self.attrs if attrs_overwrite != null then attrs = attrs_overwrite if attrs != null then for i in attrs value = null if typeof(i) == "list" then f = @i[0] if self.hasIndex(i[1]) then if typeof(@f) == "function" then value = f(self[i[1]], self) if typeof(@f) != "function" then value = self[i[1]] else if typeof(@f) == "function" then value = f(i[0], self) if typeof(@f) != "function" then value = i[0] end if else if self.hasIndex(i) then value = self[i] end if value = Utils.attr_to_s(value) key = i if typeof(key) == "list" then key = i[1] attrs_inspect.push(key + "=" + value) end for end if out = "#<" + class_name if attrs_inspect.len > 0 then out = out + " " + attrs_inspect.join(" ") out = out + ">" return out end if return self end function p = function(obj) if typeof(obj) == "map" or typeof(obj) == "list" then print(obj.inspect) else print(obj) end if end function
readme.md
basically a copy of what you get when using "p obj" in ruby
out put examples:
you can also overwrite the attributes you want to print passing the attr list as param like "print obj.inspect(["foo", "bar"])"
and you can pass a tuple (function, name) instead of a string and it will use the function to get the value of the attribute like "[@getServicesLen, "serviceslen"]" keep in mind that the function has to take 2 params (obj, scope) the obj is the attribute value if there is one with the same name and the scope is the object instance(self) there is some examples at https://www.greyrepo.xyz/posts/vega
basically a copy of what you get when using "p obj" in ruby out put examples:   you can also overwrite the attributes you want to print passing the attr list as param like "print obj.inspect(["foo", "bar"])" and you can pass a tuple (function, name) instead of a string and it will use the function to get the value of the attribute like "[@getServicesLen, "serviceslen"]" keep in mind that the function has to take 2 params (obj, scope) the obj is the attribute value if there is one with the same name and the scope is the object instance(self) there is some examples at https://www.greyrepo.xyz/posts/vega