dalexeev / gdscript-preprocessor

An export plugin for stripping comments and "conditional compilation" of GDScript.
MIT License
78 stars 1 forks source link

Replace print() with pass or replaced with ""? #1

Closed elvisish closed 6 months ago

elvisish commented 7 months ago

Love this plugin, works really well when I tested with GodotRE. I was wondering, would it be possible to replace all print() with pass? This way, no print debug messages would be exported, but functions that use them wouldn't break. Either that, or all print("") strings could be cleared to ""?

dalexeev commented 6 months ago

Hello! Thanks for your interest and testing. Yes, I have plans to add support for stripping breakpoint and assert() keywords, and global functions like print_debug(). Because even though breakpoint and assert() are not executed in release builds, they are still present in the bytecode and source code. print() and other functions can also be added as an option (disabled by default, since they are executed in release builds).

I also wanted to add some kind of macros that would allow you to inline function calls, remove arguments depending on the export target, etc. To do this, I need to improve the primitive GDScript parser. I don't want to implement a full parser, but it is necessary to distinguish between blocks and expressions (currently the parser does not distinguish if if is written on one line) and properly detect function calls.

However, this is a more difficult task and I'm not sure it's worth the effort. If I limit myself to only a rigid set of standard void functions, breakpoint and assert() keywords, then this would make the implementation much easier.

elvisish commented 6 months ago

Oh I didn't know debug() could be turned on, are there options that can be changed on the plugin?

dalexeev commented 6 months ago

Currently there are no such settings. I meant that in the future I plan to add support for stripping some function calls, and stripping print() could be a setting.

elvisish commented 6 months ago

Currently there are no such settings. I meant that in the future I plan to add support for stripping some function calls, and stripping print() could be a setting.

That would be great, this plugin has a lot of potential I think!

dalexeev commented 6 months ago

Implemented in e9186008e7b6083c585b5707c7c5f7f092640571.

Now you can customize the statement removing regex in addons/gdscript_preprocessor/options.cfg:

[statements]

removing_regex_debug=""
removing_regex_release="^(?:breakpoint|assert\\(|print_debug\\(|print_stack\\(|print\\()"

EDIT: options.cfg has been removed. Now you can change the settings in the Options tab of the Export dialog.