Set config properties with __setitem__ and type dispatching #148
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The proposed change adds the ability to configure ALE using
__setitem__
.The typed nature of C++ has probably motivated the need to write dedicated "setFloat/setInt/setString/setBool" functions. However, a unified access to these methods can be provided in python using dynamic type dispatching. The proposed changes simply checks for the type of the value argument and calls the corresponding setter in the C API.
Here's an example of the proposed change in action:
which in this case just prints
2468
. Note that the corresponding__getitem__
could also be provided. However, it is difficult to implement type dispatching since the type couldn't be inferred from the value (which is the return type, and not an argument anymore). Ideally,Settings.hxx
should expose all of the available configuration keys and their associated types. The python interface could then read the header and perform the appropriate type dispatching.The proposed changes have no effect on the existing interface other than adding a new function. All of the existing functions remain untouched and there should be no backwards compatibility issues.