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

Add support/workaround for using AutoLogOutput with Kotlin singletons #86

Open
amsam0 opened this issue Mar 15, 2024 · 0 comments
Open
Labels
enhancement New feature or request kotlin

Comments

@amsam0
Copy link

amsam0 commented Mar 15, 2024

If you store your RobotContainer and subsystems as Kotlin objects (singletons), AutoLogOutputManager will not pick up on them because they are not stored as fields.

Seeing as though finding all Kotlin objects using reflection is not feasible, it would be great to be able to call the registerFields method of AutoLogOutputManager manually to avoid storing objects as fields.

For now, we can do it via reflection:

fun registerFieldsForAutoLogOutput(root: Any) {
    val method = AutoLogOutputManager::class.java.getDeclaredMethod("registerFields", Object::class.java)
    method.isAccessible = true
    method.invoke(null, root)
}

// ... in robotInit ...
registerFieldsForAutoLogOutput(RobotContainer)

// ... in RobotContainer ...
registerFieldsForAutoLogOutput(Drive)
@amsam0 amsam0 changed the title AutoLogOutput doesn't work with Kotlin objects AutoLogOutput doesn't work with Kotlin objects when they are not stored as fields Mar 15, 2024
@jwbonner jwbonner added the kotlin label Nov 1, 2024
@jwbonner jwbonner changed the title AutoLogOutput doesn't work with Kotlin objects when they are not stored as fields Add support/workaround for using AutoLogOutput with Kotlin singletons Nov 1, 2024
@jwbonner jwbonner added the enhancement New feature or request label Nov 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request kotlin
Projects
None yet
Development

No branches or pull requests

2 participants