[Ovmsdev] Duktape Persistent Function References

Mark Webb-Johnson mark at webb-johnson.net
Sun Sep 13 18:50:01 HKT 2020


Michael,

This looks good, and works for me.

In for-3.3 branch, I am only working on the plugin code at the moment. Please commit this change to the branch.

Thanks, Mark.

> On 12 Sep 2020, at 2:26 PM, Michael Balzer <dexter at expeedo.de> wrote:
> 
> Steve,
> 
> std::function has constructors that accept function pointers, or NULL to
> create an empty function object.
> 
> std::function of course has a little overhead over a simple pointer. But
> that overhead isn't relevant for this use case. In fact, we use
> std::function already in places that are more performance & memory
> sensitive.
> 
> See: https://www.boost.org/doc/libs/1_45_0/doc/html/function/misc.html
> 
> Regards,
> Michael
> 
> 
> Am 11.09.20 um 23:31 schrieb Stephen Casner:
>> Michael,
>> 
>> Like Mark, I did not think the change would be simple.  I've used
>> functional objects before, but was not aware of std::function.  I am
>> still not quite sure how a vanilla function pointer matches this
>> type; I need to think about that more carefully.
>> 
>> Having the typedefs is a good idea even if we weren't using
>> std:function.
>> 
>>                                                        -- Steve
>> 
>> On Fri, 11 Sep 2020, Michael Balzer wrote:
>> 
>>> Mark,
>>> 
>>> Am 11.09.20 um 18:11 schrieb Michael Balzer:
>>>>> I agree it is not necessary; my suggestion is purely to clean it up
>>>>> and enhance functionality. The problem at the moment is that
>>>>> OvmsCommand execute callbacks can only be to function callbacks (not
>>>>> objects). It doesn't even use the c++ bind function callback
>>>>> mechanism (like notification, etc, for example). It is what it is,
>>>>> and changing now is very hard.
>>>> That slipped my attention, but upgrading OvmsCommand to accept any
>>>> function type should be simply changing m_execute and m_validate to
>>>> std::function, or do I miss something?
>>> Just did this locally, works perfectly. Shall I push the change or have
>>> you begun working on ovms_command?
>>> 
>>> If so, it's really just exchanging the function signatures for these types:
>>> 
>>> typedef std::function<void(int, OvmsWriter*, OvmsCommand*, int, const
>>> char* const*)> OvmsCommandExecuteCallback_t;
>>> typedef std::function<int(OvmsWriter*, OvmsCommand*, int, const char*
>>> const*, bool)> OvmsCommandValidateCallback_t;
>>> 
>>> Patch attached.
>>> 
>>> Regards,
>>> Michael
>>> 
>>> --
>>> Michael Balzer * Helkenberger Weg 9 * D-58256 Ennepetal
>>> Fon 02333 / 833 5735 * Handy 0176 / 206 989 26
>> _______________________________________________
>> OvmsDev mailing list
>> OvmsDev at lists.openvehicles.com
>> http://lists.openvehicles.com/mailman/listinfo/ovmsdev
> 
> -- 
> Michael Balzer * Helkenberger Weg 9 * D-58256 Ennepetal
> Fon 02333 / 833 5735 * Handy 0176 / 206 989 26
> 
> 
> _______________________________________________
> OvmsDev mailing list
> OvmsDev at lists.openvehicles.com
> http://lists.openvehicles.com/mailman/listinfo/ovmsdev




More information about the OvmsDev mailing list