Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to create passable from C# into C++ delegate that takes a IEnumerable as argument with SWIG?
    primarykey
    data
    text
    <p>So I have next C++ code:</p> <pre><code>#ifdef WIN32 # undef CALLBACK # define CALLBACK __stdcall #else # define CALLBACK #endif #include &lt;iostream&gt; #include &lt;vector&gt; namespace OdeProxy { typedef std::vector&lt; double &gt; state_type; typedef void (CALLBACK *System)( const state_type &amp;, state_type &amp;, const double); typedef void (CALLBACK *Observer)( const state_type &amp;, double); class Ode { public: state_type initialConditions; System system; Observer observer; double from; double to; double step; }; } </code></pre> <p>And .i file:</p> <pre><code>/* File : MyProject.i */ %module MyProject %{ #include "C++/OdeProxy.h" %} %include "std_vector.i" %include "C++/OdeProxy.h" %template(state_type) std::vector&lt;double&gt;; //// Delegate realated stuff //// %typemap(cstype) void (*)( const state_type &amp;, state_type &amp;, const double) "SystemDelegate"; %typemap(imtype) void (*)( const state_type &amp;, state_type &amp;, const double) "SystemDelegate"; %typemap(cstype) void (*)( const state_type &amp;, double) "ObserverDelegate"; %typemap(imtype) void (*)( const state_type &amp;, double) "ObserverDelegate"; </code></pre> <p>I created being inspired by this <a href="http://permalink.gmane.org/gmane.comp.programming.swig/5795" rel="noreferrer">thread</a>. Code gets generated. </p> <p>Yet I can not understand how to get code like</p> <pre><code>using OdeLibrary; namespace OdeTest { class Program { static void Main(string[] args) { //var lam = new OdeLibrary.SWIGTYPE_p_f_r_q_const__std__vector__double___double__void() var ode = new Ode{ from = 0, to = 10, initialConditions = new state_type(new[]{1,2,3}), step = 0.01, observer = (x, dxdt, t) =&gt; { return; } }; } } } </code></pre> <p>compile. Error:</p> <pre><code>Error Cannot convert lambda expression to type 'OdeLibrary.SWIGTYPE_p_f_r_q_const__std__vector__double___double__void' because it is not a delegate type </code></pre> <p>Where<code>SWIGTYPE_p_f_r_q_const__std__vector__double___double__void</code> looks like this:</p> <pre><code>/* ---------------------------------------------------------------------------- * This file was automatically generated by SWIG (http://www.swig.org). * Version 2.0.9 * * Do not make changes to this file unless you know what you are doing--modify * the SWIG interface file instead. * ----------------------------------------------------------------------------- */ namespace OdeLibrary { using System; using System.Runtime.InteropServices; public class SWIGTYPE_p_f_r_q_const__std__vector__double___double__void { private HandleRef swigCPtr; internal SWIGTYPE_p_f_r_q_const__std__vector__double___double__void(IntPtr cPtr, bool futureUse) { swigCPtr = new HandleRef(this, cPtr); } protected SWIGTYPE_p_f_r_q_const__std__vector__double___double__void() { swigCPtr = new HandleRef(null, IntPtr.Zero); } internal static HandleRef getCPtr(SWIGTYPE_p_f_r_q_const__std__vector__double___double__void obj) { return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr; } } } </code></pre> <p>So I wonder what shall be changed in <code>.i</code> file or added to c# generated wrapper to get the ability to pass my C# lambda to C++ class as delegate?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload