Changeset 3112 for libcaca


Ignore:
Timestamp:
Oct 26, 2008, 4:47:33 PM (11 years ago)
Author:
nico
Message:
  • Improve function caca_export_string
Location:
libcaca/trunk/caca-php
Files:
2 edited

Legend:

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

    r3110 r3112  
    120120        PHP_FE(caca_file_gets, NULL)
    121121        PHP_FE(caca_file_eof, NULL)
    122         PHP_FE(caca_import_memory, NULL)
     122        PHP_FE(caca_import_string, NULL)
    123123        PHP_FE(caca_import_file, NULL)
    124124        PHP_FE(caca_get_import_list, NULL)
     125        PHP_FE(caca_export_string, NULL)
    125126        PHP_FE(caca_get_export_list, NULL)
    126127        PHP_FE(caca_create_display, NULL)
     
    587588
    588589PHP_FUNCTION(caca_set_attr) {
     590        zval *_zval;
     591        long attr = 0;
     592        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll", &_zval, &attr) == FAILURE) {
     593                RETURN_FALSE;
     594        }
     595        caca_canvas_t *canvas;
     596        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
     597        RETURN_SUCCESS(caca_set_attr(canvas, attr));
    589598}
    590599
     
    945954}
    946955
    947 PHP_FUNCTION(caca_import_memory) {
     956PHP_FUNCTION(caca_import_string) {
    948957        zval *_zval;
    949958        char *src, *type;
     
    962971
    963972PHP_FUNCTION(caca_get_import_list) {
     973}
     974
     975PHP_FUNCTION(caca_export_string) {
     976        zval *_zval;
     977        char *type;
     978        long type_len;
     979        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &_zval, &type, &type_len) == FAILURE) {
     980                RETURN_FALSE;
     981        }
     982        caca_canvas_t *canvas;
     983        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
     984
     985        void *buffer;
     986        size_t len;
     987        buffer = caca_export_memory(canvas, type, &len);
     988        return_value->type = IS_STRING;
     989        return_value->value.str.len = len;
     990        return_value->value.str.val = emalloc(len);
     991        memcpy(return_value->value.str.val, buffer, len);
     992        free(buffer);
    964993}
    965994
  • libcaca/trunk/caca-php/php_caca.h

    r3110 r3112  
    138138PHP_FUNCTION(caca_file_gets);
    139139PHP_FUNCTION(caca_file_eof);
    140 PHP_FUNCTION(caca_import_memory);
     140PHP_FUNCTION(caca_import_string);
    141141PHP_FUNCTION(caca_import_file);
    142142PHP_FUNCTION(caca_get_import_list);
     143PHP_FUNCTION(caca_export_string);
    143144PHP_FUNCTION(caca_get_export_list);
    144145PHP_FUNCTION(caca_create_display);
Note: See TracChangeset for help on using the changeset viewer.