Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7775939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:45:04+00:00 2026-06-01T17:45:04+00:00

I want to create a basic ruby module for xcb for my own use.

  • 0

I want to create a basic ruby module for xcb for my own use.
I tried a basic test where I wrap header file with swig:
here is my xcb_ruby.i

%module ruxcby 
%{
#include <xcb/xcb.h>
#include <xcb/xcb_util.h>
#include <xcb/xcb_aux.h
#include <xcb/xcb_atom.h>
#include <xcb/xcb_event.h>
%}
%include "/usr/include/xcb/xproto.h"
%include "/usr/include/xcb/xcb.h"
%include "/usr/include/xcb/xcb_atom.h"
%include "/usr/include/xcb/xcb_aux.h"
%include "/usr/include/xcb/xcb_event.h"

When I try it in irb, I am able to connect to initialize connection, get information from this connection but the ruby interface is like in C. I would like to have a more object oriented interface.

For example in xcb.h there is :

typedef struct xcb_connection_t xcb_connection_t;
xcb_connection_t * xcb_connect(const char *displayname, int *screenp);
int xcb_flush( xcb_connection_t *);
uint32_t xcb_generate_id( xcb_connection_t *);
void xcb_disconnect(xcb_connection_t * );

I want to have a Connection class with methods new/connect(), flush(), generate_id() and disconnect()
here is my new xcb_ruby.i:

%module ruxcby
%{
#include <xcb/xcb.h>
#include <xcb/xproto.h>
%}
%import "/usr/include/xcb/xproto.h"

typedef struct xcb_connection_t {
} Connection;

%extend Connection 
{
  Connection(const char *displayname, int *screenp)
  {
    Connection * c;
    c = xcb_connect(displayname, screenp);
    return c;
  }
  int flush()
  {
    return xcb_flush($self);
  }
  xcb_generic_event_t *wait_for_event()
  {
    return xcb_wait_for_event($self);
  }
  void disconnect()
  {
    return xcb_disconnect($self);
  }
  uint32_t generate_id()
  {
    return xcb_generate_id($self);
  }
};

If I try to compile after I have generated the c file, I have an error:
erreur: unknown type name ‘Connection’

Can someone tell me where I am wrong?

Thanks

Edits

I have made some modifications and now I can compile it but I still get some errors:

%module ruxcby
%{
#include <xcb/xcb.h>
#include <xcb/xproto.h>
typedef struct {
  xcb_connection_t * ptr;
} Connection;
%}
%import "/usr/include/xcb/xproto.h"
%feature("autodoc" , "1");

typedef struct {
  xcb_connection_t * ptr;
} Connection;
%extend Connection {
  Connection(const char *displayname, int *screenp)
 {
    Connection * c ;
    c->ptr = xcb_connect(displayname, screenp);
    return c;
 }
 int flush()
 {  
    return xcb_flush($self->ptr);
 }
 xcb_generic_event_t *wait_for_event()
 {
    return xcb_wait_for_event($self->ptr);
 }
 int connection_has_error()
 {
    return xcb_connection_has_error($self->ptr);
 }
 void disconnect()
 {
   return xcb_disconnect($self->ptr);
 }
 uint32_t generate_id()
 {
    return xcb_generate_id($self->ptr);
 }
};

Now I can compile my module and use it:

require './ruxcby'
=> true
conn=Connection.new(nil, nil)
=> #<Ruxcby::Connection:0x0000000223dfc8>

But when I try another method I have an error:

conn.connection_has_error 
ObjectPreviouslyDeleted: Expected argument 0 of type Connection *, but got Ruxcby::Connection #<Ruxcby::

It seems that the method exist but there is still a problem when passing argument to the method.

Any ideas??

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T17:45:05+00:00Added an answer on June 1, 2026 at 5:45 pm

    I put the solution maybe it can help someone:
    When I extend the Connection class I didn’t allocated memory for my structure:

    %extend Connection {
    Connection(const char *displayname, int *screenp)
    {
      Connection * c ;
      c = (Connection * ) malloc(sizeof(Connection));
      c->ptr = xcb_connect(displayname, screenp);
      return c;
    }
    ~Connection()
    {
      free($self);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create basic low-poly 3D models to use in XNA Game Studio
I want to create basic line, bar, pie and area charts for .NET 3.5
I'm new to Sencha Touch 2. I want to create a basic example, which
I want to create a very basic 3D modeling tool. The application is supposed
I want to create a simple http proxy server that does some very basic
I'm using Visual Basic 9 (VS2008) I want to create new Tabs as and
I want create module which update list of usb devices automatically (not only mass
I simply want to create a fairly basic REST service, so that I can
I want to create a List in an ActiveX component project in Visual Basic
I want to create a small Ruby project with 10 ~ 20 classes/files. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.