1 /* 2 * libcaca Ruby bindings 3 * Copyright (c) 2007-2010 Pascal Terjan <pterjan@linuxfr.org> 4 * 2012 Sam Hocevar <sam@hocevar.net> 5 * 6 * This library is free software. It comes without any warranty, to 7 * the extent permitted by applicable law. You can redistribute it 8 * and/or modify it under the terms of the Do What the Fuck You Want 9 * to Public License, Version 2, as published by Sam Hocevar. See 10 * http://www.wtfpl.net/ for more details. 11 */ 12 13 #ifndef __COMMON_H__ 14 #define __COMMON_H__ 15 16 #define _SELF (DATA_PTR(self)) 17 18 #define get_singleton_double_list(x) \ 19 static VALUE x##_list(void) \ 20 { \ 21 VALUE ary, ary2; \ 22 char const* const* list; \ 23 \ 24 list = caca_get_##x##_list(); \ 25 ary = rb_ary_new(); \ 26 while (*list != NULL) \ 27 { \ 28 ary2 = rb_ary_new(); \ 29 rb_ary_push(ary2, rb_str_new2(*list)); \ 30 list++; \ 31 rb_ary_push(ary2, rb_str_new2(*list)); \ 32 list++; \ 33 rb_ary_push(ary, ary2); \ 34 } \ 35 \ 36 return ary; \ 37 } 38 39 #define get_double_list(x) \ 40 static VALUE x##_list(VALUE self) \ 41 { \ 42 VALUE ary, ary2; \ 43 char const* const* list; \ 44 \ 45 list = caca_get_##x##_list(_SELF); \ 46 ary = rb_ary_new(); \ 47 while (*list != NULL) \ 48 { \ 49 ary2 = rb_ary_new(); \ 50 rb_ary_push(ary2, rb_str_new2(*list)); \ 51 list++; \ 52 rb_ary_push(ary2, rb_str_new2(*list)); \ 53 list++; \ 54 rb_ary_push(ary, ary2); \ 55 } \ 56 \ 57 return ary; \ 58 } 59 60 #endif 61