Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conditional block not stripped if there are conditions inside of it? #8

Open
Invertex opened this issue Jun 30, 2024 · 2 comments
Open
Labels
documentation Improvements or additions to documentation

Comments

@Invertex
Copy link

Invertex commented Jun 30, 2024

I have a simple example, where my class derives from Resource.

It has a function like this:

func _init() -> void:
	if Engine.is_editor_hint():
		if type_exists("EditorInterface") and EditorInterface.has_method("get_inspector"):
			var selection = EditorInterface.get_inspector().get_edited_object()
			print(selection.name)

But the exported build is still throwing an error about EditorInterface not existing, meaning that code is still being included.
If I don't have that inner condition, then that is_editor_hint() block gets excluded fine, I tried with just print() inside there instead.

Is this feature not supposed to strip everything within the if Engine.is_editor_hint(): conditional block?

I also tried just stripping the function using the #~if OS.has_feature("my_feature") option but I guess it can only strip top-level variables and not functions or code inside of functions?

Thanks!

@dalexeev
Copy link
Owner

dalexeev commented Jun 30, 2024

@Invertex Hello, thanks for your question!

I can't reproduce this locally, the plugin handles it correctly:

func _init() -> void:
    if Engine.is_editor_hint():
        if type_exists("EditorInterface") and EditorInterface.has_method("get_inspector"):
            var selection = EditorInterface.get_inspector().get_edited_object()
            print(selection.name)

preprocessed to:

func _init() -> void:
    pass

Which Godot version are you using: 4.2.2 stable or 4.3 beta 2? If the latter, then I should update the documentation, since the default export mode in 4.3 (Binary Tokens) is not compatible with the plugin.

I also tried just stripping the function using the #~if OS.has_feature("my_feature") option but I guess it can only strip top-level variables and not functions or code inside of functions?

Directives can work inside functions too, although they were not intended for this purpose. It is not obvious that directives must start at the beginning of the line, indentation is not currently supported. See #7 for details.

@Invertex
Copy link
Author

Invertex commented Jul 1, 2024

Ah yes, I am using 4.3-beta2. That is a shame it doesn't work with the tokenization option, I assume there's no way to hook into the compilation pipeline before it starts the tokenization process?

When I build in "string mode" in 4.3, some plugins don't seem to compile well yet work fine when tokenization is one, so string isn't really an option, and I'd prefer not to use it for the sake of helping protect my code from casual deconstruction.

Thanks for the response and clarification on that though!

@dalexeev dalexeev added the documentation Improvements or additions to documentation label Aug 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants