How to store built in functions (such as "<") in variables

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By divinenephron
:warning: Old Version Published before Godot 3 was released.

How do I store a built in function (such as <) in a variable?

The GDScript documentation about referencing functions suggests:

var comparator = funcref(self, "<")
comparator.call_func(1, 2)

This produces the error:

Invalid call. Nonexistent function 'call_func' in base 'FuncRef'.

The result I expect in the example above is true.

:bust_in_silhouette: Reply From: divinenephron

The character < is an operator, so there is no way to store it in a variable. You can write a static function which returns its result though:

static func lt(x, y):
    return x < y

var comparator = funcref(self, "lt")
comparator.call_func(1, 2)

Thanks to bojidar_bg for their suggestions on IRC.

:bust_in_silhouette: Reply From: gau_veldt

Unlike C++ operators aren’t themselves functions you can call. Funcref will only store methods of an instance. It’s basically a form of Object.call() that you can pack into a var and courier off to another method, for example, for the _notification() of one object packing a method call into a message queue to courier off to another object’s _process() method or _draw() method.

You could also store a Funcref along with some parameters into a dictionary to cobble up a currying (baking parameters to a function call) mechanism. Actually that’s an idea for an object I should make to share in Projects.