Skip to content

Commit d36dbf6

Browse files
committed
make header C++ compatible
1 parent ae0cf1a commit d36dbf6

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

sender_capi.h

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,27 @@
2323
# define SENDER_CAPI_IMPLEMENT_GET_CAPI 0
2424
#endif
2525

26+
#ifdef __cplusplus
27+
28+
extern "C" {
29+
30+
struct sender_object;
31+
struct sender_reader;
32+
struct sender_capi;
33+
struct sender_capi_value;
34+
35+
#else /* __cplusplus */
36+
2637
typedef struct sender_object sender_object;
2738
typedef struct sender_reader sender_reader;
2839
typedef struct sender_capi sender_capi;
29-
typedef enum sender_capi_value_type sender_capi_value_type;
3040
typedef struct sender_capi_value sender_capi_value;
41+
42+
typedef enum sender_capi_value_type sender_capi_value_type;
3143
typedef enum sender_array_type sender_array_type;
3244

45+
#endif /* ! __cplusplus */
46+
3347
enum sender_capi_value_type
3448
{
3549
SENDER_CAPI_TYPE_NONE = 0,
@@ -209,7 +223,7 @@ struct sender_capi
209223
static int sender_set_capi(lua_State* L, int index, const sender_capi* capi)
210224
{
211225
lua_pushlstring(L, SENDER_CAPI_ID_STRING, strlen(SENDER_CAPI_ID_STRING)); /* -> key */
212-
void** udata = lua_newuserdata(L, sizeof(void*) + strlen(SENDER_CAPI_ID_STRING) + 1); /* -> key, value */
226+
void** udata = (void**) lua_newuserdata(L, sizeof(void*) + strlen(SENDER_CAPI_ID_STRING) + 1); /* -> key, value */
213227
*udata = (void*)capi;
214228
strcpy((char*)(udata + 1), SENDER_CAPI_ID_STRING); /* -> key, value */
215229
lua_rawset(L, (index < 0) ? (index - 2) : index); /* -> */
@@ -229,22 +243,22 @@ static const sender_capi* sender_get_capi(lua_State* L, int index, int* errorRea
229243
{
230244
if (luaL_getmetafield(L, index, SENDER_CAPI_ID_STRING) != LUA_TNIL) /* -> _capi */
231245
{
232-
void** udata = lua_touserdata(L, -1); /* -> _capi */
246+
const void** udata = (const void**) lua_touserdata(L, -1); /* -> _capi */
233247

234248
if ( udata
235249
&& (lua_rawlen(L, -1) >= sizeof(void*) + strlen(SENDER_CAPI_ID_STRING) + 1)
236250
&& (memcmp((char*)(udata + 1), SENDER_CAPI_ID_STRING,
237251
strlen(SENDER_CAPI_ID_STRING) + 1) == 0))
238252
{
239-
const sender_capi* capi = *udata; /* -> _capi */
253+
const sender_capi* capi = (const sender_capi*) *udata; /* -> _capi */
240254
while (capi) {
241255
if ( capi->version_major == SENDER_CAPI_VERSION_MAJOR
242256
&& capi->version_minor >= SENDER_CAPI_VERSION_MINOR)
243257
{ /* -> _capi */
244258
lua_pop(L, 1); /* -> */
245259
return capi;
246260
}
247-
capi = capi->next_capi;
261+
capi = (const sender_capi*) capi->next_capi;
248262
}
249263
if (errorReason) {
250264
*errorReason = 1;
@@ -264,4 +278,8 @@ static const sender_capi* sender_get_capi(lua_State* L, int index, int* errorRea
264278
}
265279
#endif /* SENDER_CAPI_IMPLEMENT_GET_CAPI */
266280

281+
#ifdef __cplusplus
282+
} /* extern "C" */
283+
#endif
284+
267285
#endif /* SENDER_CAPI_H */

0 commit comments

Comments
 (0)