Skip to content

Commit 589b240

Browse files
committed
Fix create/destroy/set/get Lua Rsvg functions.
We need an interface to be able to create/destroy/set/get the RsvgRectangle and RsvgDimensionData structs via Lua, which were missing or incomplete. Documentation was also missing, which has been updated.
1 parent e99a555 commit 589b240

File tree

3 files changed

+121
-11
lines changed

3 files changed

+121
-11
lines changed

doc/lua.yaml

Lines changed: 68 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,35 +34,53 @@ values:
3434
desc: |-
3535
Call this function to return a new cairo_font_extents_t
3636
structure. A creation function for this structure is not provided
37-
by the cairo API. After calling this, you should use
38-
tolua.takeownership() on the return value to ensure ownership is
37+
by the cairo API.
38+
39+
After calling this, you should use
40+
`tolua.takeownership(cfe)` on the return value to ensure ownership is
3941
passed properly.
4042
- name: cairo_font_extents_t:destroy(structure)
4143
desc: |-
4244
Call this function to free memory allocated by
4345
cairo_font_extents_t:create.
46+
47+
You should call `tolua.releaseownership(cfe)` before calling this function to
48+
avoid double-frees, but only if you previously called
49+
`tolua.takeownership(cfe)`
4450
- name: cairo_matrix_t:create()
4551
desc: |-
4652
Call this function to return a new cairo_matrix_t structure.
4753
A creation function for this structure is not provided by the
48-
cairo API. After calling this, you should use
49-
tolua.takeownership() on the return value to ensure ownership is
54+
cairo API.
55+
56+
After calling this, you should use
57+
`tolua.takeownership(cm)` on the return value to ensure ownership is
5058
passed properly.
5159
- name: cairo_matrix_t:destroy(structure)
5260
desc: |-
5361
Call this function to free memory allocated by
5462
cairo_matrix_t:create.
63+
64+
You should call `tolua.releaseownership(cm)` before calling this function to
65+
avoid double-frees, but only if you previously called
66+
`tolua.takeownership(cm)`
5567
- name: cairo_text_extents_t:create()
5668
desc: |-
5769
Call this function to return a new cairo_text_extents_t
5870
structure. A creation function for this structure is not provided
59-
by the cairo API. After calling this, you should use
60-
tolua.takeownership() on the return value to ensure ownership is
71+
by the cairo API.
72+
73+
After calling this, you should use
74+
`tolua.takeownership(cte)` on the return value to ensure ownership is
6175
passed properly.
6276
- name: cairo_text_extents_t:destroy(structure)
6377
desc: |-
6478
Call this function to free memory allocated by
6579
cairo_text_extents_t:create.
80+
81+
You should call `tolua.releaseownership(cte)` before calling this function to
82+
avoid double-frees, but only if you previously called
83+
`tolua.takeownership(cte)`
6684
- name: conky_build_arch
6785
desc: |-
6886
A string containing the build architecture for this
@@ -123,3 +141,47 @@ values:
123141
124142
NOTE: This table is only defined when X support is
125143
enabled.
144+
- name: RsvgRectangle:create()
145+
desc: |-
146+
Call this method to return a new RsvgRectangle
147+
structure. A creation function for this structure is not provided
148+
by the Rsvg API.
149+
150+
After calling this, you should use `tolua.takeownership(rect)` on the return
151+
value to ensure ownership is passed properly.
152+
- name: RsvgRectangle:destroy()
153+
desc: |-
154+
Call this method to free memory allocated by
155+
`RsvgRectangle:create`.
156+
157+
You should call `tolua.releaseownership(rect)` before calling this function to
158+
avoid double-frees, but only if you previously called
159+
`tolua.takeownership(rect)`
160+
- name: RsvgRectangle:set(x, y, width, height)
161+
desc: |-
162+
Sets the values of an existing RsvgRectangle.
163+
- name: RsvgRectangle:get()
164+
desc: |-
165+
Gets the values of an existing RsvgRectangle.
166+
- name: RsvgDimensionData:create()
167+
desc: |-
168+
Call this method to return a new RsvgDimensionData
169+
structure. A creation function for this structure is not provided
170+
by the Rsvg API.
171+
172+
After calling this, you should use `tolua.takeownership(rect)` on the return
173+
value to ensure ownership is passed properly.
174+
- name: RsvgDimensionData:destroy()
175+
desc: |-
176+
Call this method to free memory allocated by
177+
`RsvgDimensionData:create`.
178+
179+
You should call `tolua.releaseownership(dd)` before calling this function to
180+
avoid double-frees, but only if you previously called
181+
`tolua.takeownership(dd)`
182+
- name: RsvgDimensionData:set(x, y, width, height)
183+
desc: |-
184+
Sets the values of an existing RsvgDimensionData.
185+
- name: RsvgDimensionData:get()
186+
desc: |-
187+
Gets the values of an existing RsvgDimensionData.

lua/librsvg-helper.h

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,16 @@
2929
#include <librsvg/rsvg.h>
3030
#include <stdlib.h>
3131

32-
RsvgDimensionData *rsvgDimensionDataCreate(void) {
32+
RsvgDimensionData *rsvg_dimension_data_create(void) {
3333
return (RsvgDimensionData *)calloc(1, sizeof(RsvgDimensionData));
3434
}
3535

36-
void rsvgDimensionDataGet(RsvgDimensionData *dd, int *width, int *height,
37-
double *em, double *ex) {
36+
void rsvg_dimension_data_destroy(RsvgDimensionData *pointer) {
37+
if (pointer) { free(pointer); }
38+
}
39+
40+
void rsvg_dimension_data_get(RsvgDimensionData *dd, int *width, int *height,
41+
double *em, double *ex) {
3842
if (dd) {
3943
*width = dd->width;
4044
*height = dd->height;
@@ -43,6 +47,16 @@ void rsvgDimensionDataGet(RsvgDimensionData *dd, int *width, int *height,
4347
}
4448
}
4549

50+
void rsvg_dimension_data_set(RsvgDimensionData *dd, int width, int height,
51+
double em, double ex) {
52+
if (dd) {
53+
dd->width = width;
54+
dd->height = height;
55+
dd->em = em;
56+
dd->ex = ex;
57+
}
58+
}
59+
4660
RsvgPositionData *rsvgPositionDataCreate(void) {
4761
return (RsvgPositionData *)calloc(1, sizeof(RsvgPositionData));
4862
}
@@ -78,4 +92,30 @@ int rsvg_destroy_handle(RsvgHandle *handle) {
7892
return 0;
7993
}
8094

95+
RsvgRectangle *rsvg_rectangle_create(void) {
96+
return calloc(1, sizeof(RsvgRectangle));
97+
}
98+
99+
void rsvg_rectangle_destroy(RsvgRectangle *rect) { free(rect); }
100+
101+
void rsvg_rectangle_set(RsvgRectangle *rect, double x, double y, double width,
102+
double height) {
103+
if (rect) {
104+
rect->x = x;
105+
rect->y = y;
106+
rect->width = width;
107+
rect->height = height;
108+
}
109+
}
110+
111+
void rsvg_rectangle_get(RsvgRectangle *rect, double *x, double *y,
112+
double *width, double *height) {
113+
if (rect) {
114+
*x = rect->x;
115+
*y = rect->y;
116+
*width = rect->width;
117+
*height = rect->height;
118+
}
119+
}
120+
81121
#endif /* _LIBRSVG_HELPER_H_ */

lua/rsvg.pkg

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,12 @@ typedef struct _RsvgDimensionData {
6161
int height;
6262
double em;
6363
double ex;
64-
static tolua_outside RsvgDimensionData * rsvgDimensionDataCreate @ create();
65-
tolua_outside void rsvgDimensionDataGet @ get(int * width, int * height,
64+
static tolua_outside RsvgDimensionData* rsvg_dimension_data_create @ create();
65+
static tolua_outside void rsvg_dimension_data_destroy @ destroy(RsvgDimensionData *);
66+
tolua_outside void rsvg_dimension_data_get @ get(int * width, int * height,
6667
double * em, double * ex);
68+
tolua_outside void rsvg_dimension_data_set @ get(int width, int height,
69+
double em, double ex);
6770
} RsvgDimensionData;
6871

6972
/**
@@ -82,6 +85,11 @@ typedef struct _RsvgRectangle {
8285
double y;
8386
double width;
8487
double height;
88+
89+
static tolua_outside RsvgRectangle* rsvg_rectangle_create @ create();
90+
static tolua_outside void rsvg_rectangle_destroy @ destroy(RsvgRectangle *pointer);
91+
tolua_outside void rsvg_rectangle_set @ set(double x, double y, double width, double height);
92+
tolua_outside void rsvg_rectangle_get @ get(double *x, double *y, double *width, double *height);
8593
} RsvgRectangle;
8694

8795
const char *rsvg_handle_get_base_uri (RsvgHandle * handle);

0 commit comments

Comments
 (0)