I am talking about providing scripting capabilities at runtime. I am interested in your thoughts/suggestions regarding the subject and wanted to share the results of my frankensteinian experiments. Also I have no idea if anybody else has done something like this, nor am I sure there isn't some obvious solution.
I've started experimenting because: 1. Giving scripting possibilities to users is nice for modding and tools. 2. I use a DSL for dialogs and such which needs to interact with GDScript. 3. Godot only gives you Expression, which is very limited
My approach: 1. Tokenize the text 2. Copy the GDScript grammar as far as sensible (there is a reference in the docs) in a Recursive Descent Parser. Then for each statement we can figure out if it is an assignmentstatement, or an if-statement etc. 3. For expressions I use Expression.parse(...) Expression.execute() and assemble the available variables from the current scope, this gives me integration with GDScript 4. You can register vars (including nodes) and Funcrefs from GDscript to be able to use them in the embedded scripting language 5. Do a bunch of hacky stuff to make things work as expected, e.g. x[0][0] = 4 is not easy to do, and I automatically insert '.call_func' for funcrefs so I can write 'f()' instead of 'f.call_func()'
Results: 1. I think there should be a Node for this. Also safety needs to be taken into consideration. Providing Assignment and Declaration besides Expression might be enough. 2. What I've done is doable, it works good enough for the simple stuff I need it for, I can do loops, if-branches, declare and assign variables, call functions. Due to hacks it's far from bulletproof though.