Double clicking on user-defined function call makes editor go to function definition

LoadLevel("Crossroads1")

When I double click on this line of code, it would be amazing if the editor would go to the definition of this function. If the definition is in a currently unopened script, it should open that script in a new tab and then navigate to it.

In a similar vein, it would be really useful to be able to right-click on this line of code:

function LoadLevel(levelName)

And be able to select “Find all references” which would give me a list of scripts and line numbers where this function is currently being called. Right now if I refactor a function call I basically have to run my game over and over again and weed out obsolete calls to the old function.

3 Likes

Can’t you use global find to find references?

1 Like

I didn’t know about global find. That is really useful.

“Find All References” is slightly more powerful though because it doesn’t just do a dumb string match.

If I have two function definitions:

function LoadLevel(levelName)
function LoadLevel(levelName, preLoadNext)

“Find All References” is smart enough to know the arity of the function and only return function calls of the matching overload.

This is most useful in the case where you implement “Find All References” on variables as well. I just did a global search and I have 150 mentions of the string “char”, but only 5 mentions of “char” the global variable defined in my main game script.

The thing is, you can’t overload in Lua, and you can leave arguments off…

1 Like

What if I have multiple scripts that contain a function called “LoadLevel”?

1 Like

No overloads? You’ve got to be kidding.

You lex it so you know which one it is. It can’t be ambiguous at runtime or you will get a namespace collision, which even in Lua has to be a runtime error.

Well… technically you can just check if an argument is nil or not and work around it that way.

Lua programmers like bolting stuff onto their language that should have been standard.

So you get always metatable thunk it in.

http://lua-users.org/wiki/OverloadedFunctions

That’s the beauty of Lua, is it not?

1 Like

I would suggest Ctrl+click rather than double click. I use double click to select words

2 Likes

Yikes, that is not how I’d ever do it. You just typecheck if you need to, or you avoid it.

1 Like

I think Lua is just too relaxed for this to work.

function f(x)
   return tostring(x+1)
end
if condition then
   function f(n)
      return n..1
   end
end
f(1)

It’s impossible to tell which f you’re referring to.

Whenever I do overloads I use a single function and check the types of the arguments. That way I don’t have to have a ton of different functions. In my case it would also be impossible to tell what function I’m calling. The absolute best you can do would be to search the name of the function and jump to the closest definition.

1 Like