Can I embed gdscript engine in an app such that it can directly run user-editable scripts from its UI?

Godot Version

4.6

Question

I’m interested in making a standalone tool that can generate images entirely from scripted source code. To save myself from defining an entire new language i thought it would be nice to use gdscript. I’m still very new to godot and learning the basics but are there ways to easily embed gdscript in this way? I’m picturing something analogous to how OpenSCAD works for scripting 3D models, in case anyone is familiar with that software.

There are custom 2D drawing commands, you may need to queue_redraw() often for updates

  var file := FileAccess.create_temp(FileAccess.WRITE, "my_script", "gd")
  file.store_string("extends Node\nfunc _ready():\n\tprint(\"Hallo!\")")
  file.flush()
  add_child(load(file.get_path()).new())

This just prints “Hallo!” in the output console. So, creating a temporary file with your script is the way I found so far, but I’m sure there’s an easier way. I’d be happy to hear about it.

But in the end you will probably have problems when it comes to error handling. This is why I wrote my own little scripting language in GDScript, but you can’t define new functions in it (not yet, at least).