R
R
rovied2015-08-20 15:42:26
Lua
rovied, 2015-08-20 15:42:26

How to compare class instance table - Lua OOP?

How to compare the table of class instances in the class itself (if it is possible, if not, tell me your version)?
There is one class, inside the class there is a local table (for example, let's call points) with the coordinates of various points (they serve to display images). I create two instances of the class (each instance has its own point coordinates in the points table) and in each instance I need to iterate over the points table of other instances (except myself). So what are the ways to do this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Lerg, 2015-08-20
@rovied

Store objects in some publicly accessible table (array). Inside the method, loop through this table and compare points as you like, while excluding yourself from the if loop.

for i = 1, #allObjects do
  local o = allObjects[i]
  if self ~= o then
    self:comparePoints(self.points, o.points)
  end
end

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question