title: Rubymotion and Pointers to Structs
body: <p>I'm experimenting with cocosmotion, a Rubymotion implementation of Cocos2d. In the tutorial I'm working through, I have a method that takes a struct as an argument. I consulted the Rubymotion and MacRuby docs, but can't figure out how to instantiate a new object based on the struct I need. I think the main issue is that the struct starts with a lowercase letter and Ruby thinks it's a local variable when I try to work with it.</p>
  
  <p>I believe I have the same problem as stated here:
  <a href="https://github.com/MacRuby/MacRuby/issues/121">https://github.com/MacRuby/MacRuby/issues/121</a></p>
  
  <p>Is there a solution or workaround?</p>
  
  <p>The struct is defined in Objective-C like so:</p>
  
  <pre><code> typedef struct _ccTexParams {
           GLuint  minFilter;
           GLuint  magFilter;
           GLuint  wrapS;
           GLuint  wrapT;
   } ccTexParams;
  </code></pre>
  
  <p>The method I'm trying to call expects a ccTexParams struct.</p>
  
  <p>Here is what I've tried:</p>
  
  <pre><code>            @mysprite = Pointer.new("{ccTexParams=
              {GLUint=GL_LINEAR_MIPMAP_LINEAR}
              {GLUint=GL_LINEAR}
              {GLUint=GL_CLAMP_TO_EDGE}
              {GLUint=GL_CLAMP_TO_EDGE}}", 4)
  </code></pre>
  
  <p>When I try it this way:</p>
  
  <pre><code>        @mysprite = Pointer.new(:object, 4)
  
          @mysprite[0] = GL_LINEAR_MIPMAP_LINEAR 
          @mysprite[1] = GL_LINEAR
          @mysprite[2] = GL_CLAMP_TO_EDGE
          @mysprite[3] = GL_CLAMP_TO_EDGE
  </code></pre>
  
  <p>The runtime error is:</p>
  
  <pre><code>expected instance of Pointer of type `{_ccTexParams=IIII}', got `@' (TypeError)
  </code></pre>
  
  <p>I also tried:</p>
  
  <pre><code>@mysprite = Pointer.new("_ccTexParams", 4)
  
          @mysprite[0] = GL_LINEAR_MIPMAP_LINEAR 
          @mysprite[1] = GL_LINEAR
          @mysprite[2] = GL_CLAMP_TO_EDGE
          @mysprite[3] = GL_CLAMP_TO_EDGE
  </code></pre>
  
  <p>The error:</p>
  
  <pre><code>Can't find pointer description for type `_ccTexParams'
  </code></pre>
  
  <p>I've also tried to replace it as CcTexParams, _ccTexParams, and just ccTexParams in a bunch of different ways, no versions of it work.</p>
  
  <p>I tried this:</p>
  
  <pre><code>@mysprite = CcTexParams.new
  @mysprite.minFilter = GL_LINEAR_MIPMAP_LINEAR 
  @mysprite.magFilter = GL_LINEAR
  @mysprite.wrapS = GL_CLAMP_TO_EDGE
  @mysprite.wrapT = GL_CLAMP_TO_EDGE
  </code></pre>
  
  <p>RubyMotion complains it <code>expected an instance of Pointer, got '#&lt;CcTexParams minFilter=9987 magFilter=9729 wrapS=33071 wrapT=33071&gt;' (CcTexParams) (TypeError)</code></p>
  
  <p>I tried just passing <code>[GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE]</code> directly to the method.  It complains that it <code>expected a Pointer but got an Array</code>.</p>
  
  <p>Perhaps I should just rename <code>ccTexParams</code> in the lib to something like <code>CCTexParams</code>? I'm guessing that's not an ideal workaround.</p>