Ignore:
Timestamp:
Oct 30, 2008, 1:18:07 AM (11 years ago)
Author:
nico
Message:
  • Remove php function caca_create_event
  • caca_get_event return false if type == CACA_EVENT_NONE otherwise return a new php resource
  • Adapt sample program demo.php
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcaca/trunk/caca-php/php_caca.c

    r3138 r3142  
    2020
    2121static function_entry caca_functions[] = {
    22         PHP_FE(caca_create_event, NULL)
    2322        PHP_FE(caca_create_canvas, NULL)
    2423        PHP_FE(caca_set_canvas_size, NULL)
     
    382381}
    383382
    384 //------- PHP Binding's specific functions ----------//
    385 
    386 //TODO: register new resources in caca_get_event and remove caca_create_event
    387 PHP_FUNCTION(caca_create_event) {
    388         caca_event_t *event;
    389         event = emalloc(sizeof(caca_event_t));
    390         if (!event) {
    391                 RETURN_FALSE;
    392         }
    393         ZEND_REGISTER_RESOURCE(return_value, event, le_caca_event);
    394 }
    395 
    396383//------- Caca's functions ----------------//
    397384
     
    17151702
    17161703PHP_FUNCTION(caca_get_event) {
    1717         zval *_zval1, *_zval2 = NULL;
     1704        zval *_zval = NULL;
    17181705        long g, aa = 0;
    1719         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl|rl", &_zval1, &g, &_zval2, &aa) == FAILURE) {
     1706        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl|l", &_zval, &g, &aa) == FAILURE) {
    17201707                RETURN_FALSE;
    17211708        }
    17221709        caca_display_t *display;
    1723         ZEND_FETCH_RESOURCE(display, caca_display_t*, &_zval1, -1, PHP_CACA_DISPLAY_RES_NAME, le_caca_display);
    1724 
    1725         caca_event_t *event = NULL;
    1726         if (_zval2) {
    1727                 ZEND_FETCH_RESOURCE(event, caca_event_t*, &_zval2, -1, PHP_CACA_EVENT_RES_NAME, le_caca_event);
    1728         }
    1729         RETURN_LONG(caca_get_event(display, g, event, aa));
     1710        ZEND_FETCH_RESOURCE(display, caca_display_t*, &_zval, -1, PHP_CACA_DISPLAY_RES_NAME, le_caca_display);
     1711
     1712        caca_event_t *event = emalloc(sizeof(caca_event_t));
     1713        if (!event) {
     1714                RETURN_FALSE;
     1715        }
     1716
     1717        caca_get_event(display, g, event, aa);
     1718
     1719        if (caca_get_event_type(event) == CACA_EVENT_NONE) {
     1720                efree(event);   
     1721                RETURN_FALSE;
     1722        }
     1723        ZEND_REGISTER_RESOURCE(return_value, event, le_caca_event);
    17301724}
    17311725
Note: See TracChangeset for help on using the changeset viewer.