Mercerenies / gdlisp

Lisp on the Godot platform
GNU General Public License v3.0
140 stars 1 forks source link

GDScript Built-in Functions with Optional Arguments #78

Closed Mercerenies closed 2 years ago

Mercerenies commented 2 years ago

Several built-in GDScript functions take optional arguments. For instance,

Color ColorN ( String name, float alpha=1.0 )

In principle, we should treat this as the following in GDLisp

(defn ColorN (name &opt alpha))

but that will be treated in GDScript as though it was declared

func ColorN(name, alpha)

77 gets us closer, treating it as

func ColorN(name, alpha = null)

But this has the problem that, if we #' it to get a function reference, then the reference will behave in a subtly incorrect way. Namely,

(funcall #'ColorN "foo")

will fill in null for the second argument, rather than using the appropriate default of 1.0.

Mercerenies commented 2 years ago

Relevant functions: Color8, ColorN, assert, range, var2bytes, bytes2var.

Mercerenies commented 2 years ago

b213773 implements range. We will be wrapping all GDScript functions which have optional arguments and using call magic (the same call magic as used in #79, in fact) to forward all direct calls.

Mercerenies commented 2 years ago

Closed by 48487b5