<commit_before>-- Copyright (c) 2009-2011 Incremental IP Limited
-- see LICENSE for license information

local error, getmetatable, pairs, setmetatable, rawget, type =
      error, getmetatable, pairs, setmetatable, rawget, type

module(...)


-- Types -----------------------------------------------------------------------

local object = _M
object.__index = object
object.__typename = "object"
object.__typeinfo = { object = true, [object] = true }


function object:new_class(o, new_type_name)
  o = o or {}
  if new_type_name then o.__typename = new_type_name end
  local parent_typeinfo = self.__typeinfo
  o.__typeinfo = { [o.__typename] = true, [o] = true }
  if self.__typeinfo then
    for k, v in pairs(self.__typeinfo) do
      o.__typeinfo[k] = v
    end
  end
  o.__index = o
  return setmetatable(o, self)
end


function object:new(o)
  return setmetatable(o or {}, self)
end


local core_type_info =
{
  boolean = { boolean = true },
  ["function"] = { ["function"] = true },
  ["nil"] = { ["nil"] = true },
  number = { number = true },
  string = { string = true },
  table = { table = true },
  thread = { thread = true },
  userdata = { userdata = true },
}


function object.typeinfo(o)
  local mt = getmetatable(o)
  return mt and mt.__typeinfo or core_type_info[type(o)]
end


function object.typename(o)
  local mt = getmetatable(o)
  return mt and mt.__typename or type(o)
end


-- EOF -------------------------------------------------------------------------
<commit_msg>rima.lib.object might be lua52-ready now<commit_after>-- Copyright (c) 2009-2012 Incremental IP Limited
-- see LICENSE for license information

local error, getmetatable, pairs, setmetatable, rawget, type =
      error, getmetatable, pairs, setmetatable, rawget, type


------------------------------------------------------------------------------

local core_type_info =
{
  boolean               = { boolean       = true },
  ["function"]          = { ["function"]  = true },
  ["nil"]               = { ["nil"]       = true },
  number                = { number        = true },
  string                = { string        = true },
  table                 = { table         = true },
  thread                = { thread        = true },
  userdata              = { userdata      = true },
}


------------------------------------------------------------------------------

local object = {}
object.__index = object
object.__typename = "object"
object.__typeinfo = { object = true, [object] = true }


function object:new_class(o, new_type_name)
  o = o or {}
  if new_type_name then o.__typename = new_type_name end
  local parent_typeinfo = self.__typeinfo
  o.__typeinfo = { [o.__typename] = true, [o] = true }
  if self.__typeinfo then
    for k, v in pairs(self.__typeinfo) do
      o.__typeinfo[k] = v
    end
  end
  o.__index = o
  return setmetatable(o, self)
end


function object:new(o)
  return setmetatable(o or {}, self)
end


function object.typeinfo(o)
  local mt = getmetatable(o)
  return mt and mt.__typeinfo or core_type_info[type(o)]
end


function object.typename(o)
  local mt = getmetatable(o)
  return mt and mt.__typename or type(o)
end


------------------------------------------------------------------------------

return object

------------------------------------------------------------------------------

{'fraction_non_alphanumeric': 0.23733892718010188, 'fraction_numerical': 0.005394066526820497, 'mean_word_length': 1.7226753670473083, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4476544', 'n_tokens_mistral': 969, 'n_tokens_neox': 933, 'n_words': 274}