Compile GDScript hook scripts to Elixir source.
GDScript -> lexer -> AST -> codegen -> .ex -> mix compile -> .beamThe generated .ex is written to disk and kept. It is formatted, readable,
and it is what appears in stack traces -- so a script author debugs generated
Elixir that reads like their GDScript, rather than an opaque runtime.
Nothing is interpreted at run time. The output is ordinary Elixir that compiles to the same BEAM bytecode a hand-written plugin does.
Supported subset
func with default arguments, var / const, assignment and the compound
operators, if / elif / else, return, arithmetic, comparison, and /
or / not, arrays, dictionaries, indexing, field access, calls into the
gamend contexts (Economy.grant(...)), and calls to other funcs in the
same file.
Anything else -- for, while, class_name, signal, engine types -- is a
compile error naming the line. There is no best-effort mode: a construct is
either translated exactly or refused.
Summary
Functions
Compile every script in a plugin together, returning
[{module_name, elixir_source}].
Compile path and return {module_name, elixir_source}.
Compile GDScript source into Elixir source for module.
The module name a script compiles to when none is given.
Functions
Compile every script in a plugin together, returning
[{module_name, elixir_source}].
Scripts are parsed first and then generated, so a script naming itself with
class_name Foo is reachable from every other one as Foo.method(...) --
Godot's own mechanism -- and a wrong name or argument count across files is
still a compile error.
Reference mode is decided once for the whole plugin: a reference handed from one script to another has to stay a reference, and mixing modes across files would break that.
Compile path and return {module_name, elixir_source}.
The module name defaults to Gamend.Modules.<CamelizedBasename>, matching
where a hand-written plugin puts its hooks module.
Compile GDScript source into Elixir source for module.
Raises Gamend.GDScript.CompileError with a file and line for anything
outside the supported subset.
The module name a script compiles to when none is given.