[cairo] const usage in API

Hakki Dogusan dogusanh at tr.net
Fri Nov 9 15:17:57 PST 2007


Hi,

Carl Worth wrote:

Thanks for reply.

> On Fri, 09 Nov 2007 23:59:16 +0200, Hakki Dogusan wrote:
>> Some functions use const for parameters, but some not. Is there a rule?
> 
> Yes.
> 
>> cairo_public void
>> cairo_scaled_font_extents (cairo_scaled_font_t  *scaled_font,
>>       	cairo_font_extents_t *extents);
>>
>> cairo_public void
>> cairo_set_matrix (cairo_t *cr,
>> 	const cairo_matrix_t *matrix);
> 
> In the case of cairo_scaled_font_extents, that function is *writing*
> to the extents structure you pass in, (definitely not const).
> 
> In the case of cairo_set_matrix, that function is only *reading* from
> the matrix you pass in---the const guarantees that it will not be
> modified.
> 
> For things like the cairo_scaled_font_t* and cairo_t*, those are
> opaque data types. The user of the API can't look inside them so can't
> care if the structures will be modified or not.
> 

I was actually interested only with scaled_font parameter (It seems I 
don't have the ability to ask the right question :( ).

I'm trying to make my lua binding to have a consistent usage (user (me!) 
should only need Cairo API listing and remember following rules);
if Cairo API has:
- a const parameter then lua usage is the same
- a non-const parameter then lua binding will return that

scaled_font, extents = 	cairo.scaled_font_extents (scaled_font, extents);

cr = cairo.set_matrix (cr, matrix);

cr, x, y = cairo.user_to_device (cr, x, y);

etc.



> -Carl


--
Regards,
Hakki Dogusan


More information about the cairo mailing list