Closed edubart closed 10 months ago
Agreed, I was actually missing it too a couple of times. It should essentially be a shortcut for boolean args (bla=true
vs just bla
). I guess the reason why I didn't implement this to begin with is that it complicates the parser (also because sokol-args doesn't expect args to start with '-')
Hmm ok, on the web it works by accident, because the URLSearchParams
object fill missing values with empty strings, e.g. here:
https://github.com/floooh/sokol/blob/751fc4c14a0cb80130ad8014f965ac62c7e89d34/sokol_args.h#L723-L724
const val
will be an empty string.
I'll see if I can fix the 'native' arg parser function to work the same way.
PS: I probably still need to change behaviour a bit, because currently sargs_value()
for a non-existing arg returns an empty string, so standalone args can't have an empty value string too.
Ok, fixed via https://github.com/floooh/sokol/pull/896
See the updated documentation for caveats (key-only args have an empty value string, but can be checked with sargs_exists()
or sargs_boolean()
.
Also check the updated tests (https://github.com/floooh/sokol/blob/10f2c9c06699a47b910de370deea11e709df97fe/tests/functional/sokol_args_test.c#L256-L302)
Thanks for improving this @floooh !
I am using
sokol_args.h
as a library to handle command line arguments in an apps that can be compiled to WebAssembly or native (Linux in my case). When I useemrun myapp.html -- -myarg
, while the argument-myarg
is listed for WebAssembly, it's omitted in native, so there is a different behavior between native and WebAssembly.I noticed this comment in
sokol_args.h
:Actually single keys works in WebAssembly, but not in native yet, I guess this behavior was not really defined in the library. I think the library should start defining this, so native could be improved to handle single key arguments like WebAssembly is.