Replies: 2 comments 6 replies
-
This definitely seems useful! You can implement your own renderer directly in the language, it doesn't need to be a "feature" of the language. You can see an example of how this is done for TOML here: https://github.com/apple/pkl-pantry/tree/main/packages/pkl.toml |
Beta Was this translation helpful? Give feedback.
-
If you are using pkl-swift and want to avoid the Pkl dependency at runtime, you can eval Pkl into messagepack bytes during the build, and then embed these bytes inside your application. You can then decode the resulting bytes into the structs generated by To eval into bytes, take a look at To decode msgpack, take a look at I actually just created a sample application that uses this pattern for Go here, hopefully this is helpful: https://github.com/bioball/pkl-go-examples/tree/build-time-eval/buildtimeeval Having Pkl data render to literals in the target language isn't a goal for us, because it's likely to be error-prone. It's hard to ensure that this rendering will match how the decoder/code generator works in that library. |
Beta Was this translation helpful? Give feedback.
-
Hi, just starting to explore pkl for a project and we're really enjoying what we've seen so far.
One thing that surprised us though was that while you can evaluate pkl to YAML, JSON etc, you can't do so for Swift and Kotlin. We're using the code-gen in one part of the project to load in a pkl file at runtime and this works great, but there are other places where it would be more convenient to render directly to the language.
Our current workaround is Pkl → YAML → SwiftGen which works, but isn't that best as while you can set
omitNullProperties = false
, anynull
properties end up typed asAny?
.A simple example:
Settings.pkl
settings.yml
Settings.swift (via SwiftGen)
So we're wondering if there would be any appetite for such a feature?
Beta Was this translation helpful? Give feedback.
All reactions