0
function Tags.get_forward_backward_by_key(way,data,key)
  local forward = way:get_value_by_key(key .. ':forward')
  local backward = way:get_value_by_key(key .. ':backward')

  if not forward or not backward then
     local common = way:get_value_by_key(key)

     if (data.oneway) then
        if data.is_forward_oneway then
           forward = forward or common
        end
        if data.is_reverse_oneway then
           backward = backward or common
        end
     else
        forward = forward or common
        backward = backward or common
     end
  end

  return forward, backward
end

I'm reading this code and it's not easy to understand. I was wondering, what is the meaning of ":" and what is "data.oneway"? Any references are greatly appreciated.

EDIT: I just learned that this is a special syntax called object-oriented calls. An expression like o:foo(x) is just another way to write o.foo(o, x), that is, to call o.foo adding o as a first extra argument.

kkxx
  • 571
  • 1
  • 5
  • 16
  • 1
    `data.is_forward_oneway` seems to be referring to something else in the code that we can't see. – Corsaka Nov 07 '19 at 12:20
  • So, where to find this element "get_value_by_key"? – kkxx Nov 07 '19 at 13:20
  • 1
    Wherever `way` or its metatable is created. Not in this sample, that is. – Aki Nov 07 '19 at 13:34
  • You mean, wait to see when way is used, i.e., the function Tags.get_forward_backward_by_key is called? – kkxx Nov 07 '19 at 13:36
  • When `Tags.get_forward_backward_by_key` is called it is expected to have three arguments. First argument `way` is expected to have a member with key `get_value_by_key` which is a function. `:` in this case is basically `way["get_value_by_key"](way, key .. ':forward')`. Before the `Tags.get_forward...` is called there is an object created and passed to it as its first argument. Look for it. – Aki Nov 07 '19 at 13:53
  • 1
    if you understood what `:` does you may as well just delete this post. it is of no use to anyone else. its right in the Lua Manual where they explain how to clal functions... https://www.lua.org/manual/5.3/manual.html#3.4.10 – Piglet Nov 08 '19 at 15:44

0 Answers0