Ian Botsford
11/20/2024, 6:15 PMfoo_init, foo_bar, and foo_baz. Calling foo_init before calling foo_bar or foo_baz is mandatory (else errors occur). I can see several (bad) options:
• I can add call-site guards every place I need to invoke foo_bar and foo_baz but that's boilerplate
• I can eagerly call foo_init in some early part of my own application but that could be wasteful since I don't yet know if I'm going to invoke foo_bar or foo_baz
• I can wrap access into a singleton (e.g., object LibFoo) with an init block that performs the foo_init call but this requires manually binding every libfoo API into a singleton method
What am I missing? What are other people doing?Sargun Vohra
11/21/2024, 8:16 AMloke
11/21/2024, 2:13 PMloke
11/21/2024, 2:14 PMIan Botsford
11/21/2024, 4:07 PMinit { } for which calls the C library's initializer. I'm not stuck on that as a solution but it's closer to how I would write "real" Kotlin code that needed to enforce certain constraints at runtime such as bootstrapping.loke
11/22/2024, 2:28 PMinit methods on object instances called in Kotlin native? In Java they're only called when the class is loaded, but Kotlin native calls them at startup?kevin.cianfarini
11/22/2024, 4:35 PMFoo class that exposes bar and baz functions. When that class is constructed ensure foo_init was called. To avoid multiple calls to foo_init you could wrap it in some lazy initializer that only fires upon first request and is internal to your library.Ian Botsford
11/22/2024, 5:00 PMIan Botsford
11/22/2024, 5:05 PM