Page 1 of 1

Setting a default value for argument type ".p-utf8"

Posted: Sun Jan 05, 2020 4:09 pm
by hippy
Hi All,

Is it possible to set a default value in a prototype for an argument of type .p-utf8

Eg:

Code: Select all

PrototypeC ___igShowFontSelector_pr(label.p-utf8)  ; void igShowFontSelector(const char* label);
I'd like to do something like:

Code: Select all

PrototypeC ___igShowFontSelector_pr(label.p-utf8="Default Value")  ; void igShowFontSelector(const char* label);
But I cannot, I can with a .s but my library only supports UTF8, I only can do

Code: Select all

(label.p-utf8=0)
Cheers,
Hippy

Re: Setting a default value for argument type ".p-utf8"

Posted: Sun Jan 05, 2020 4:47 pm
by mk-soft
Unfortunately not possible, because the parameter is a pointer to a UTF8 string at runtime and is released after the call.

If a features request...

Alternatively, check for null pointers in the function and use the default value.

Code: Select all

;-TOP

ProcedureC test(*UTF8_String)
  If *UTF8_String
    Debug PeekS(*UTF8_String, -1, #PB_UTF8)
  Else
    Debug "Default Value"
  EndIf
EndProcedure

; ----

PrototypeC externTest(label.p-utf8=0)

*CallTest.externTest = @test()

*CallTest()
*CallTest("Hello World")

Re: Setting a default value for argument type ".p-utf8"

Posted: Mon Jan 06, 2020 2:06 am
by hippy
:( Thanks for the quick reply!