Ignore:
Timestamp:
Oct 26, 2008, 3:14:58 PM (12 years ago)
Author:
nico
Message:
  • Centralize caca's error managment (in macro RETURN_SUCCESS)
  • Add binding for 2 new functions
  • Fix a bug in examples/example1.php
Location:
libcaca/trunk/caca-php
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • libcaca/trunk/caca-php/examples/demo.php

    r3109 r3110  
    11#!/usr/bin/php5
    22<?
     3/*
     4 *  demo.php      demo for libcaca php binding
     5 *  Copyright (c) 2008 Nicolas Vion <nico@yojik.eu>
     6 *
     7 *  This file is a Php port of the official libcaca's sample program "demo.c"
     8 *  which is:
     9 *  Copyright (c) 2003 Sam Hocevar <sam@zoy.org>
     10 *
     11 *  This program is free software. It comes without any warranty, to
     12 *  the extent permitted by applicable law. You can redistribute it
     13 *  and/or modify it under the terms of the Do What The Fuck You Want
     14 *  To Public License, Version 2, as published by Sam Hocevar. See
     15 *  http://sam.zoy.org/wtfpl/COPYING for more details.
     16 */
    317
    418function main() {
     
    1327        }
    1428
    15 
    1629        caca_set_display_time($dp, 40000);
    1730
     
    2235        display_menu($cv, $dp, $bounds, $outline);
    2336        caca_refresh_display($dp);
    24 
    2537
    2638        /* Go ! */
  • libcaca/trunk/caca-php/examples/example1.php

    r3106 r3110  
    4343$ix = $iy = 1;
    4444
    45 while (caca_get_event($display, CACA_EVENT_KEY_PRESS)) {
     45while (!caca_get_event($display, CACA_EVENT_KEY_PRESS)) {
    4646        // In case of resize ...
    4747        if ($x + caca_get_canvas_width($pig) - 1 >= caca_get_canvas_width($canvas) || $x < 0 )
  • libcaca/trunk/caca-php/php_caca.c

    r3109 r3110  
    4545        PHP_FE(caca_flip, NULL)
    4646        PHP_FE(caca_flop, NULL)
     47        PHP_FE(caca_rotate_180, NULL)
    4748        PHP_FE(caca_rotate_left, NULL)
    4849        PHP_FE(caca_rotate_right, NULL)
     
    5758        PHP_FE(caca_attr_to_ansi_fg, NULL)
    5859        PHP_FE(caca_attr_to_ansi_bg, NULL)
     60        PHP_FE(caca_attr_to_rgb12_fg, NULL)
     61        PHP_FE(caca_attr_to_rgb12_bg, NULL)
     62        PHP_FE(caca_attr_to_argb64, NULL)
     63        PHP_FE(caca_utf8_to_utf32, NULL)
     64        PHP_FE(caca_utf32_to_utf8, NULL)
     65        PHP_FE(caca_utf32_to_cp437, NULL)
     66        PHP_FE(caca_cp437_to_utf32, NULL)
     67        PHP_FE(caca_utf32_to_ascii, NULL)
     68        PHP_FE(caca_utf32_is_fullwidth, NULL)
    5969        PHP_FE(caca_draw_line, NULL)
    6070        PHP_FE(caca_draw_polyline, NULL)
     
    323333        RETURN_STRING(str, 0);
    324334
     335#define RETURN_SUCCESS(i) \
     336        RETURN_BOOL((i) == 0);
     337
    325338//------- PHP Binding's specific functions ----------//
    326339
     
    359372        caca_canvas_t *canvas;
    360373        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
    361         RETURN_BOOL(caca_set_canvas_size(canvas, width, height) == 0);
     374        RETURN_SUCCESS(caca_set_canvas_size(canvas, width, height));
    362375}
    363376
     
    406419        caca_canvas_t *canvas;
    407420        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
    408         RETURN_BOOL(caca_gotoxy(canvas, x, y) == 0);
     421        RETURN_SUCCESS(caca_gotoxy(canvas, x, y));
    409422}
    410423
     
    433446                RETURN_FALSE;
    434447        }
    435         RETURN_BOOL(caca_put_char(canvas, x, y, str[0]) == 0);
     448        RETURN_SUCCESS(caca_put_char(canvas, x, y, str[0]));
    436449}
    437450
     
    456469        caca_canvas_t *canvas;
    457470        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
    458         RETURN_BOOL(caca_put_str(canvas, x, y, str) == 0);
     471        RETURN_SUCCESS(caca_put_str(canvas, x, y, str));
    459472}
    460473
     
    473486        caca_canvas_t *canvas;
    474487        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
    475         RETURN_BOOL(caca_set_canvas_handle(canvas, x, y) == 0);
     488        RETURN_SUCCESS(caca_set_canvas_handle(canvas, x, y));
    476489}
    477490
     
    500513                ZEND_FETCH_RESOURCE(mask, caca_canvas_t*, &_zval3, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
    501514        }
    502         RETURN_BOOL(caca_blit(dst, x, y, src, NULL) == 0);
     515        RETURN_SUCCESS(caca_blit(dst, x, y, src, NULL));
    503516}
    504517
     
    511524        caca_canvas_t *canvas;
    512525        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
    513         RETURN_BOOL(caca_set_canvas_boundaries(canvas, x, y, width, height) == 0);
     526        RETURN_SUCCESS(caca_set_canvas_boundaries(canvas, x, y, width, height));
    514527}
    515528
     
    517530        caca_canvas_t *canvas;
    518531        FETCH_CANVAS(canvas);
    519         RETURN_BOOL(caca_invert(canvas) == 0);
     532        RETURN_SUCCESS(caca_invert(canvas));
    520533}
    521534
     
    523536        caca_canvas_t *canvas;
    524537        FETCH_CANVAS(canvas);
    525         RETURN_BOOL(caca_flip(canvas) == 0);
     538        RETURN_SUCCESS(caca_flip(canvas));
    526539}
    527540
     
    529542        caca_canvas_t *canvas;
    530543        FETCH_CANVAS(canvas);
    531         RETURN_BOOL(caca_flop(canvas) == 0);
     544        RETURN_SUCCESS(caca_flop(canvas));
    532545}
    533546
     
    535548        caca_canvas_t *canvas;
    536549        FETCH_CANVAS(canvas);
    537         RETURN_BOOL(caca_rotate_180(canvas) == 0);
     550        RETURN_SUCCESS(caca_rotate_180(canvas));
    538551}
    539552
     
    541554        caca_canvas_t *canvas;
    542555        FETCH_CANVAS(canvas);
    543         RETURN_BOOL(caca_rotate_left(canvas) == 0);
     556        RETURN_SUCCESS(caca_rotate_left(canvas));
    544557}
    545558
     
    547560        caca_canvas_t *canvas;
    548561        FETCH_CANVAS(canvas);
    549         RETURN_BOOL(caca_rotate_right(canvas) == 0);
     562        RETURN_SUCCESS(caca_rotate_right(canvas));
    550563}
    551564
     
    553566        caca_canvas_t *canvas;
    554567        FETCH_CANVAS(canvas);
    555         RETURN_BOOL(caca_stretch_left(canvas) == 0);
     568        RETURN_SUCCESS(caca_stretch_left(canvas));
    556569}
    557570
     
    559572        caca_canvas_t *canvas;
    560573        FETCH_CANVAS(canvas);
    561         RETURN_BOOL(caca_stretch_right(canvas) == 0);
     574        RETURN_SUCCESS(caca_stretch_right(canvas));
    562575}
    563576
    564577PHP_FUNCTION(caca_get_attr) {
     578        zval *_zval;
     579        long x, y = 0;
     580        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll", &_zval, &x, &y) == FAILURE) {
     581                RETURN_FALSE;
     582        }
     583        caca_canvas_t *canvas;
     584        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
     585        RETURN_LONG(caca_get_attr(canvas, x, y));
    565586}
    566587
     
    569590
    570591PHP_FUNCTION(caca_put_attr) {
     592        zval *_zval;
     593        long x, y, attr = 0;
     594        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlll", &_zval, &x, &y, &attr) == FAILURE) {
     595                RETURN_FALSE;
     596        }
     597        caca_canvas_t *canvas;
     598        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
     599        RETURN_SUCCESS(caca_put_attr(canvas, x, y, attr));
    571600}
    572601
     
    579608        caca_canvas_t *canvas;
    580609        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
    581         RETURN_BOOL(caca_set_color_ansi(canvas, foreground, background) == 0);
     610        RETURN_SUCCESS(caca_set_color_ansi(canvas, foreground, background));
    582611}
    583612
     
    592621
    593622PHP_FUNCTION(caca_attr_to_ansi_bg) {
     623}
     624
     625PHP_FUNCTION(caca_attr_to_rgb12_fg) {
     626}
     627
     628PHP_FUNCTION(caca_attr_to_rgb12_bg) {
     629}
     630
     631PHP_FUNCTION(caca_attr_to_argb64) {
     632}
     633
     634PHP_FUNCTION(caca_utf8_to_utf32) {
     635}
     636
     637PHP_FUNCTION(caca_utf32_to_utf8) {
     638}
     639
     640PHP_FUNCTION(caca_utf32_to_cp437) {
     641}
     642
     643PHP_FUNCTION(caca_cp437_to_utf32) {
     644}
     645
     646PHP_FUNCTION(caca_utf32_to_ascii) {
     647}
     648
     649PHP_FUNCTION(caca_utf32_is_fullwidth) {
    594650}
    595651
     
    606662                RETURN_FALSE;
    607663        }
    608         RETURN_BOOL(caca_draw_line(canvas, xa, ya, xb, yb, str[0]) == 0);
     664        RETURN_SUCCESS(caca_draw_line(canvas, xa, ya, xb, yb, str[0]));
    609665}
    610666
     
    620676        caca_canvas_t *canvas;
    621677        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
    622         RETURN_BOOL(caca_draw_thin_line(canvas, xa, ya, xb, yb) == 0);
     678        RETURN_SUCCESS(caca_draw_thin_line(canvas, xa, ya, xb, yb));
    623679}
    624680
     
    638694                RETURN_FALSE;
    639695        }
    640         RETURN_BOOL(caca_draw_circle(canvas, x, y, r, str[0]) == 0);
     696        RETURN_SUCCESS(caca_draw_circle(canvas, x, y, r, str[0]));
    641697}
    642698
     
    653709                RETURN_FALSE;
    654710        }
    655         RETURN_BOOL(caca_draw_ellipse(canvas, xa, ya, xb, yb, str[0]) == 0);
     711        RETURN_SUCCESS(caca_draw_ellipse(canvas, xa, ya, xb, yb, str[0]));
    656712}
    657713
     
    664720        caca_canvas_t *canvas;
    665721        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
    666         RETURN_BOOL(caca_draw_thin_ellipse(canvas, xa, ya, xb, yb) == 0);
     722        RETURN_SUCCESS(caca_draw_thin_ellipse(canvas, xa, ya, xb, yb));
    667723}
    668724
     
    679735                RETURN_FALSE;
    680736        }
    681         RETURN_BOOL(caca_fill_ellipse(canvas, xa, ya, xb, yb, str[0]) == 0);
     737        RETURN_SUCCESS(caca_fill_ellipse(canvas, xa, ya, xb, yb, str[0]));
    682738}
    683739
     
    694750                RETURN_FALSE;
    695751        }
    696         RETURN_BOOL(caca_draw_box(canvas, xa, ya, xb, yb, str[0]) == 0);
     752        RETURN_SUCCESS(caca_draw_box(canvas, xa, ya, xb, yb, str[0]));
    697753}
    698754
     
    705761        caca_canvas_t *canvas;
    706762        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
    707         RETURN_BOOL(caca_draw_thin_box(canvas, xa, ya, xb, yb) == 0);
     763        RETURN_SUCCESS(caca_draw_thin_box(canvas, xa, ya, xb, yb));
    708764}
    709765
     
    716772        caca_canvas_t *canvas;
    717773        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
    718         RETURN_BOOL(caca_draw_cp437_box(canvas, xa, ya, xb, yb) == 0);
     774        RETURN_SUCCESS(caca_draw_cp437_box(canvas, xa, ya, xb, yb));
    719775}
    720776
     
    731787                RETURN_FALSE;
    732788        }
    733         RETURN_BOOL(caca_fill_box(canvas, xa, ya, xb, yb, str[0]) == 0);
     789        RETURN_SUCCESS(caca_fill_box(canvas, xa, ya, xb, yb, str[0]));
    734790}
    735791
     
    746802                RETURN_FALSE;
    747803        }
    748         RETURN_BOOL(caca_draw_triangle(canvas, xa, ya, xb, yb, xc, yc, str[0]) == 0);
     804        RETURN_SUCCESS(caca_draw_triangle(canvas, xa, ya, xb, yb, xc, yc, str[0]));
    749805}
    750806
     
    757813        caca_canvas_t *canvas;
    758814        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
    759         RETURN_BOOL(caca_draw_thin_triangle(canvas, xa, ya, xb, yb, xc, yc) == 0);
     815        RETURN_SUCCESS(caca_draw_thin_triangle(canvas, xa, ya, xb, yb, xc, yc));
    760816}
    761817
     
    772828                RETURN_FALSE;
    773829        }
    774         RETURN_BOOL(caca_fill_triangle(canvas, xa, ya, xb, yb, xc, yc, str[0]) == 0);
     830        RETURN_SUCCESS(caca_fill_triangle(canvas, xa, ya, xb, yb, xc, yc, str[0]));
    775831}
    776832
     
    9511007        caca_display_t *display;
    9521008        FETCH_DISPLAY(display);
    953         RETURN_BOOL(caca_refresh_display(display) == 0);
     1009        RETURN_SUCCESS(caca_refresh_display(display));
    9541010}
    9551011
     
    9621018        caca_display_t *display;
    9631019        ZEND_FETCH_RESOURCE(display, caca_display_t*, &_zval, -1, PHP_CACA_DISPLAY_RES_NAME, le_caca_display);
    964         RETURN_BOOL(caca_set_display_time(display, value) == 0);
     1020        RETURN_SUCCESS(caca_set_display_time(display, value));
    9651021}
    9661022
     
    9921048        caca_display_t *display;
    9931049        ZEND_FETCH_RESOURCE(display, caca_display_t*, &_zval, -1, PHP_CACA_DISPLAY_RES_NAME, le_caca_display);
    994         RETURN_BOOL(caca_set_display(display, str) == 0);
     1050        RETURN_SUCCESS(caca_set_display(display, str));
    9951051}
    9961052
     
    10031059        caca_display_t *display;
    10041060        ZEND_FETCH_RESOURCE(display, caca_display_t*, &_zval, -1, PHP_CACA_DISPLAY_RES_NAME, le_caca_display);
    1005         RETURN_BOOL(caca_set_mouse(display, value) == 0);
     1061        RETURN_SUCCESS(caca_set_mouse(display, value));
    10061062}
    10071063
     
    10141070        caca_display_t *display;
    10151071        ZEND_FETCH_RESOURCE(display, caca_display_t*, &_zval, -1, PHP_CACA_DISPLAY_RES_NAME, le_caca_display);
    1016         RETURN_BOOL(caca_set_cursor(display, value) == 0);
     1072        RETURN_SUCCESS(caca_set_cursor(display, value));
    10171073}
    10181074
  • libcaca/trunk/caca-php/php_caca.h

    r3108 r3110  
    6363PHP_FUNCTION(caca_flip);
    6464PHP_FUNCTION(caca_flop);
     65PHP_FUNCTION(caca_rotate_180);
    6566PHP_FUNCTION(caca_rotate_left);
    6667PHP_FUNCTION(caca_rotate_right);
     
    7576PHP_FUNCTION(caca_attr_to_ansi_fg);
    7677PHP_FUNCTION(caca_attr_to_ansi_bg);
     78PHP_FUNCTION(caca_attr_to_rgb12_fg);
     79PHP_FUNCTION(caca_attr_to_rgb12_bg);
     80PHP_FUNCTION(caca_attr_to_argb64);
     81PHP_FUNCTION(caca_utf8_to_utf32);
     82PHP_FUNCTION(caca_utf32_to_utf8);
     83PHP_FUNCTION(caca_utf32_to_cp437);
     84PHP_FUNCTION(caca_cp437_to_utf32);
     85PHP_FUNCTION(caca_utf32_to_ascii);
     86PHP_FUNCTION(caca_utf32_is_fullwidth);
    7787PHP_FUNCTION(caca_draw_line);
    7888PHP_FUNCTION(caca_draw_polyline);
Note: See TracChangeset for help on using the changeset viewer.