[OSRM-talk] adding way id and direction to output

Jens Thiele karme at karme.de
Wed May 8 14:11:31 UTC 2013


Emil Tin <ZF0F at tmf.kk.dk> writes:

> In afraid I don't really understand what you mean. But you can now (in the modes branch) use:
>
> way.speed = 80          -- set speed for both directions
> way.forward.speed = 50  -- set speed in forward direction
> way.backward.speed = 50 -- set speed in backward direction
>
> And same for mode.
>
> You can also read way.speed, which will return -1 if forward/backward
> speed are not the same, otherwise it returns the speed.  Of course you
> can also read way.forward.speed and way.backward.speed.

i would just remove way.speed

jens

PS:
to produce the above behaviour (way.speed sets both / not reading) in
pure lua one can use lua's metatable __newindex.

something like this works:

lua> function fakeway(id,tags)
lua>    local fakeway = {id = id,
lua>                     tags = {Find = function(dummy,x) return tags[x] or "" ; end},
lua>                     forward = {speed = 0, mode = 0},
lua>                     backward = {speed = 0, mode = 0}}
lua>    setmetatable(fakeway, {__newindex = function(t,k,v) rawset(rawget(t,'forward'),k,v); rawset(rawget(t,'backward'),k,v); end})
lua>    return fakeway
lua> end

lua> print(fakeway(1,{foo='bar'}))
table: 0xb410f0
lua> x=fakeway(1,{foo='bar'})
lua> print(x);
table: 0xb4c730
lua> print(x.forward.speed);
0
lua> x.speed=10
lua> print(x.forward.speed);
10
lua> print(x.backward.speed);
10



More information about the OSRM-talk mailing list