Browse Source

* Add php binding for 8 new caca's functions

tags/v0.99.beta17
Nicolas Vion nico 16 years ago
parent
commit
4172dc244f
2 changed files with 78 additions and 1 deletions
  1. +1
    -1
      caca-php/examples/example1.php
  2. +77
    -0
      caca-php/php_caca.c

+ 1
- 1
caca-php/examples/example1.php View File

@@ -1,4 +1,4 @@
#!/usr/bin/php5 #!/usr/bin/php5
<? <?


echo caca_get_version()."\n";
echo caca_put_str()."\n";

+ 77
- 0
caca-php/php_caca.c View File

@@ -314,6 +314,13 @@ PHP_MINIT_FUNCTION(caca) {
} \ } \
ZEND_FETCH_RESOURCE(event, caca_event_t*, &_zval, -1, PHP_CACA_EVENT_RES_NAME, le_caca_event); ZEND_FETCH_RESOURCE(event, caca_event_t*, &_zval, -1, PHP_CACA_EVENT_RES_NAME, le_caca_event);


#define RETURN_CHAR(c) \
char *str = emalloc(2); \
str[0] = c; \
str[1] = '\0'; \
RETURN_STRING(str, 0);


//-------CACA'S FUNCTIONS----------------// //-------CACA'S FUNCTIONS----------------//


PHP_FUNCTION(caca_create_canvas) { PHP_FUNCTION(caca_create_canvas) {
@@ -331,6 +338,14 @@ PHP_FUNCTION(caca_unmanage_canvas) {
} }


PHP_FUNCTION(caca_set_canvas_size) { PHP_FUNCTION(caca_set_canvas_size) {
zval *_zval;
long width, height = 0;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll", &_zval, &width, &height) == FAILURE) {
RETURN_FALSE;
}
caca_canvas_t *canvas;
ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
RETURN_BOOL(caca_set_canvas_size(canvas, width, height) == 0);
} }


PHP_FUNCTION(caca_get_canvas_width) { PHP_FUNCTION(caca_get_canvas_width) {
@@ -375,6 +390,7 @@ PHP_FUNCTION(caca_gotoxy) {
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll", &_zval, &x, &y) == FAILURE) { if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll", &_zval, &x, &y) == FAILURE) {
RETURN_FALSE; RETURN_FALSE;
} }

caca_canvas_t *canvas; caca_canvas_t *canvas;
ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas); ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
RETURN_BOOL(caca_gotoxy(canvas, x, y) == 0); RETURN_BOOL(caca_gotoxy(canvas, x, y) == 0);
@@ -393,21 +409,61 @@ PHP_FUNCTION(caca_get_cursor_y) {
} }


PHP_FUNCTION(caca_put_char) { PHP_FUNCTION(caca_put_char) {
zval *_zval;
long x, y, c = 0;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlll", &_zval, &x, &y, &c) == FAILURE) {
RETURN_FALSE;
}

caca_canvas_t *canvas;
ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
RETURN_BOOL(caca_put_char(canvas, x, y, c) == 0);
} }


PHP_FUNCTION(caca_get_char) { PHP_FUNCTION(caca_get_char) {
zval *_zval;
long x, y = 0;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll", &_zval, &x, &y) == FAILURE) {
RETURN_FALSE;
}

caca_canvas_t *canvas;
ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
RETURN_CHAR(caca_get_char(canvas, x, y));
} }


PHP_FUNCTION(caca_put_str) { PHP_FUNCTION(caca_put_str) {
zval *_zval;
char *str;
long x, y, str_len = 0;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlls", &_zval, &x, &y, &str, &str_len) == FAILURE) {
RETURN_FALSE;
}

caca_canvas_t *canvas;
ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
RETURN_BOOL(caca_put_str(canvas, x, y, str) == 0);
} }


PHP_FUNCTION(caca_printf) { PHP_FUNCTION(caca_printf) {
} }


PHP_FUNCTION(caca_clear_canvas) { PHP_FUNCTION(caca_clear_canvas) {
caca_canvas_t *canvas;
FETCH_CANVAS(canvas);
RETURN_LONG(caca_clear_canvas(canvas));
} }


PHP_FUNCTION(caca_set_canvas_handle) { PHP_FUNCTION(caca_set_canvas_handle) {
zval *_zval;
long x, y = 0;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll", &_zval, &x, &y) == FAILURE) {
RETURN_FALSE;
}

caca_canvas_t *canvas;
ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
RETURN_BOOL(caca_set_canvas_handle(canvas, x, y) == 0);
} }


PHP_FUNCTION(caca_get_canvas_handle_x) { PHP_FUNCTION(caca_get_canvas_handle_x) {
@@ -423,9 +479,30 @@ PHP_FUNCTION(caca_get_canvas_handle_y) {
} }


PHP_FUNCTION(caca_blit) { PHP_FUNCTION(caca_blit) {
zval *_zval1, *_zval2, *_zval3;
long x, y = 0;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllrr", &_zval1, &x, &y, &_zval2, &_zval3) == FAILURE) {
RETURN_FALSE;
}

caca_canvas_t *dst, *src, *mask;
ZEND_FETCH_RESOURCE(dst, caca_canvas_t*, &_zval1, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
ZEND_FETCH_RESOURCE(src, caca_canvas_t*, &_zval2, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
ZEND_FETCH_RESOURCE(mask, caca_canvas_t*, &_zval3, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);

RETURN_BOOL(caca_blit(dst, x, y, src, mask) == 0);
} }


PHP_FUNCTION(caca_set_canvas_boundaries) { PHP_FUNCTION(caca_set_canvas_boundaries) {
zval *_zval;
long x, y, width, height = 0;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllll", &_zval, &x, &y, &width, &height) == FAILURE) {
RETURN_FALSE;
}

caca_canvas_t *canvas;
ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
RETURN_BOOL(caca_set_canvas_boundaries(canvas, x, y, width, height) == 0);
} }


PHP_FUNCTION(caca_invert) { PHP_FUNCTION(caca_invert) {


Loading…
Cancel
Save