Is there a way to dynamically parse multiline-strings as gdscript ?

Godot Version

v4.3.stable.official [77dcf97d8]

Question

Hello world !
I’m aware of the Expression class in order to parse one-liners of gdscript.
But what about more complex scripts ?

I’m currently writing a MUD client, and users have the possibility via one CodeEdit widget to provide small pieces of code (in gdscript obviously), and notably declaring functions.

At first I tried to export the custom code to a temporary file and simply load it, but the whole application crashes if the syntax is invalid, and I found no way to prevent it.

A simple way to avoid crashing would be enough. Detailed parsing errors would be quite a bonus.

Thanks everybody.

The script class?

Thanks for your reply.

The script class?

Actually, I didn’t find how I could use the Script class.

I’m moreover already using the GDScript class which inherits from Script.
Script class is abstract and thus cannot be instantiated.

On my client, once the player has set some code, it goes through this block of code :

	self.extra_script = GDScript.new()
	self.extra_script.source_code = new_src

	if self.extra_script.reload() != OK:
		print("new source code is invalid")
		return false

Unfortunately, when trying to call extra_script.reload, it does a little bit more than just returning something else than OK, it crashes :grimacing: