Thanks
@Tetrachromat that makes sense but I was trying to figure out a way to make it backward compatible with the existing interpolate_linear function, which can handle either ascending or descending values with no other external helper functions required. Now that I know what's going on, I can easily make my table ascending and simply use your code. The problem was that I tried to use your code as a retrofit in my algorithm and it "blew up" because a while ago I had happened to make my settings table descending. Took me a while to track it down.
And the way I was thinking about it ... maybe I'm wrong ... is that even though I added a bunch of seemingly duplicate code with only a few things changed in the duplicated parts, it wouldn't really be that much more of a hit at execution time. Code doesn't execute the "else" part when the "then" part is called by the "if" statement, does it? If that's true then it only does one extra comparison between the first and last row of column index 1, and then runs the corresponding then or else branch.
I guess what I'm suggesting is that it somehow should be taken into account if your code replaces the existing function in AM4.1, as
@Corjan suggested he would. If that's the case, it's not really backward compatible because the current version is direction agnostic. Doesn't really matter to me how it gets fixed code wise, I just proposed a solution that's the most efficient I could think of at the time. I'm sure it could be collapsed into more elegant if/then/else statements than I did in the example.
Really not trying to be a pain in the backside here, I'm just trying to help and save somebody else the troubleshooting I did last night to figure it out.
EDIT: I was just about to hit send and then I realized I'm 5 minutes late for a Zoom call! In the mean time, I see that you edited your previous post to add that you don't need to do the local t outside the function which is better but it still requires the external sort function. I was hoping there's a way to do it all internally to the function to maintain backwards compatibility. I'm sure you much more experienced Lua coders will figure something out, I'm just raising a flag and proposing a solution. That's my $0.02.