# HG changeset patch # User Mikael Hallendal # Date 1207670826 -7200 # Node ID de2e3f3631c91a69ca5143d4dbfb5e3b0277c305 # Parent 3dafc8376e9bd148d51f0be3da73e7c15e2f45e0 initial code for ruby bindings diff -r 3dafc8376e9b -r de2e3f3631c9 bindings/ruby/extconf.rb --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bindings/ruby/extconf.rb Tue Apr 08 18:07:06 2008 +0200 @@ -0,0 +1,13 @@ +require 'pkg-config' + +PACKAGE_NAME = "loudmouth" +PACKAGE_ID = "loudmouth" + +# SRCDIR = File.expand_path(File.dirname(__FILE__) + '/src') + +require 'mkmf' + +PKGConfig.have_package("loudmouth-1.0", 1, 3, 4) or exit 1 +PKGConfig.have_package("glib-2.0", 2, 4, 0) or exit 1 + +create_makefile("loudmouth") diff -r 3dafc8376e9b -r de2e3f3631c9 bindings/ruby/rlm-connection.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bindings/ruby/rlm-connection.c Tue Apr 08 18:07:06 2008 +0200 @@ -0,0 +1,56 @@ +#include "rloudmouth.h" + +void +conn_mark (LmConnection *self) +{ +} + +void +conn_free (LmConnection *self) +{ + lm_connection_unref (self); +} + +VALUE +conn_allocate(VALUE klass) +{ + LmConnection *conn = lm_connection_new (NULL); + + return Data_Wrap_Struct (klass, conn_mark, conn_free, conn); +} + +VALUE +conn_initialize(VALUE self, VALUE server) +{ + LmConnection *conn; + + Data_Get_Struct (self, LmConnection, conn); + + if (!rb_respond_to (server, rb_intern ("to_s"))) { + rb_raise (rb_eArgError, "server should respond to to_s"); + } else { + VALUE str_val = rb_funcall (server, rb_intern ("to_s"), 0); + lm_connection_set_server (conn, StringValuePtr (str_val)); + } + + return self; +} + +VALUE +conn_open (VALUE block) +{ + return Qtrue; +} + +void +Init_lm_connection (VALUE lm_mLM) +{ + VALUE lm_mConnection; + + lm_mConnection = rb_define_class_under (lm_mLM, "Connection", + rb_cObject); + + rb_define_alloc_func (lm_mConnection, conn_allocate); + rb_define_method (lm_mConnection, "initialize", conn_initialize, 1); + rb_define_method (lm_mConnection, "open", conn_open, 1); +} diff -r 3dafc8376e9b -r de2e3f3631c9 bindings/ruby/rloudmouth.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bindings/ruby/rloudmouth.c Tue Apr 08 18:07:06 2008 +0200 @@ -0,0 +1,12 @@ +#include "rloudmouth.h" + +void +Init_loudmouth (void) +{ + VALUE lm_mLM; + + lm_mLM = rb_define_module ("LM"); + + Init_lm_connection (lm_mLM); +} + diff -r 3dafc8376e9b -r de2e3f3631c9 bindings/ruby/rloudmouth.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bindings/ruby/rloudmouth.h Tue Apr 08 18:07:06 2008 +0200 @@ -0,0 +1,12 @@ +#ifndef __RLM_H__ +#define __RLM_H__ + +#include +#include +#include + +extern void Init_loudmouth (void); +extern void Init_lm_connection (VALUE lm_mLM); + +#endif /* __RLM_H__ */ +