IRC Log Viewer » #firebreath » 2016-01-21

IRC Nick Time (GMT-7) Message
Colorlit 00:01 taxilian, i dont know, may be i deployed plugin wrong, but while my description if a plugin json empty, host automatically disconnecting. Can not debug now ;\
GreenMario 15:01 hey Richard, noticing some interesting behavior with calling an API from JS on firebreath plugin.
taxilian 15:01 yeah?
GreenMario 15:01 I used to have an API that took a JSObjectPtr callback as the only parameter until now. and from JS I would call this api by passing in a calback. everything worked so far so good
I tried adding an optional parameter to this api in c++. something like (JSOBjectPtr xyz, bool value = true)
and when I call it from JS using the existing code, it errors out.
can you think of a reason why it would do so?
taxilian 15:01 so this is a C++ api that is called from JS?
GreenMario 15:01 yeah, I just use registerMethod to set it up as an API for JS to use
taxilian 15:01 then the issue is that JSAPI can't tell that you had a default value for bool value
if you want to make it optional you'll have to either use boost::optional or FB::variant
e.g. (JSObjectPtr xyz, boost::optional<bool> value)
GreenMario 15:01 hmm, I see.
taxilian 15:01 remember that it's actually using templates to figure out what your function takes and generate code to do the conversion
GreenMario 15:01 so is it safe to write it like (JSObjectPtr xyz, boost::optional<bool> value = true)?
taxilian 15:01 then you do if (value) { bool realValue = *value; } else { /* value wasn't provided */ }
I honestly don't know
GreenMario 15:01 yeah, that makes sense.
taxilian 15:01 I'd probably just do if (!value) { realValue = true; }
I think you might be able to use tristatebool from boost as well; I forget
I added support for a bunch of things, but boost::optional is the simplest, though it's a bit weird when you use it with a bool since you have the if (value) and if (*value) being different things =]
GreenMario 15:01 no worries. I'll try it out and let you know how it goes. thanks a bunch :-)
taxilian 15:01 good luck!
GreenMario 15:01 boost::optional<bool> worked! I just did the same thing as you said i.e. if(value) {xyz = *value} else {xyz = true}
thanks again Richard. saved a bunch of time :-)
taxilian 15:01 you're welcome =]
GreenMario 16:01 actually, just out of curiosity, why would boost::optional<bool> work whereas boost::tribool won't? Is firebreath handling boost::optional in registerMethod templates explicitly?
taxilian 16:01 yes
but I think tribool does work
GreenMario 16:01 hmm, I tried but it didn't. maybe I made some error. I would trust if you say it does.
taxilian 16:01 https://github.com/firebreath/FireBreath/blob/2.0/src/ScriptingCore/variant.cpp#L65 we do have handling for it...
but maybe it still requires a value
https://github.com/firebreath/FireBreath/blob/2.0/src/ScriptingCore/ConverterUtils.h#L63
GreenMario 16:01 hmm, interesting. then it must work. ok, my error then :-)
taxilian 16:01 there could still be a bug in the code
but it looks good to me
I haven't tested it recently
GreenMario 16:01 let me confirm once again
GreenMario 16:01 confirmed. tribool works as well. so basically you have handling for tristate everything in firebreath pretty much, which can be used as a way to have optional parameters. neat stuff :-)
error I was making was literally missing a "!" because it's been a long day
taxilian 21:01 lol. yep, that'd do it