Skip to content

Commit 052c9c8

Browse files
committed
make header C++ compatible
1 parent 3b61c30 commit 052c9c8

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

notify_capi.h

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66
#define NOTIFY_CAPI_VERSION_MINOR 0
77
#define NOTIFY_CAPI_VERSION_PATCH 1
88

9-
typedef struct notify_notifier notify_notifier;
10-
typedef struct notify_capi notify_capi;
11-
129
#ifndef NOTIFY_CAPI_IMPLEMENT_SET_CAPI
1310
# define NOTIFY_CAPI_IMPLEMENT_SET_CAPI 0
1411
#endif
@@ -17,6 +14,20 @@ typedef struct notify_capi notify_capi;
1714
# define NOTIFY_CAPI_IMPLEMENT_GET_CAPI 0
1815
#endif
1916

17+
#ifdef __cplusplus
18+
19+
extern "C" {
20+
21+
struct notify_notifier;
22+
struct notify_capi;
23+
24+
#else /* __cplusplus */
25+
26+
typedef struct notify_notifier notify_notifier;
27+
typedef struct notify_capi notify_capi;
28+
29+
#endif /* ! __cplusplus */
30+
2031
/**
2132
* Type for pointer to function that may be called if an error occurs.
2233
* ehdata: void pointer that is given in notify method (see below)
@@ -100,7 +111,7 @@ struct notify_capi
100111
static int notify_set_capi(lua_State* L, int index, const notify_capi* capi)
101112
{
102113
lua_pushlstring(L, NOTIFY_CAPI_ID_STRING, strlen(NOTIFY_CAPI_ID_STRING)); /* -> key */
103-
void** udata = lua_newuserdata(L, sizeof(void*) + strlen(NOTIFY_CAPI_ID_STRING) + 1); /* -> key, value */
114+
void** udata = (void**) lua_newuserdata(L, sizeof(void*) + strlen(NOTIFY_CAPI_ID_STRING) + 1); /* -> key, value */
104115
*udata = (void*)capi;
105116
strcpy((char*)(udata + 1), NOTIFY_CAPI_ID_STRING); /* -> key, value */
106117
lua_rawset(L, (index < 0) ? (index - 2) : index); /* -> */
@@ -120,22 +131,22 @@ static const notify_capi* notify_get_capi(lua_State* L, int index, int* errorRea
120131
{
121132
if (luaL_getmetafield(L, index, NOTIFY_CAPI_ID_STRING) != LUA_TNIL) /* -> _capi */
122133
{
123-
void** udata = lua_touserdata(L, -1); /* -> _capi */
134+
const void** udata = (const void**) lua_touserdata(L, -1); /* -> _capi */
124135

125136
if ( udata
126137
&& (lua_rawlen(L, -1) >= sizeof(void*) + strlen(NOTIFY_CAPI_ID_STRING) + 1)
127138
&& (memcmp((char*)(udata + 1), NOTIFY_CAPI_ID_STRING,
128139
strlen(NOTIFY_CAPI_ID_STRING) + 1) == 0))
129140
{
130-
const notify_capi* capi = *udata; /* -> _capi */
141+
const notify_capi* capi = (const notify_capi*) *udata; /* -> _capi */
131142
while (capi) {
132143
if ( capi->version_major == NOTIFY_CAPI_VERSION_MAJOR
133144
&& capi->version_minor >= NOTIFY_CAPI_VERSION_MINOR)
134145
{ /* -> _capi */
135146
lua_pop(L, 1); /* -> */
136147
return capi;
137148
}
138-
capi = capi->next_capi;
149+
capi = (const notify_capi*) capi->next_capi;
139150
}
140151
if (errorReason) {
141152
*errorReason = 1;
@@ -155,4 +166,8 @@ static const notify_capi* notify_get_capi(lua_State* L, int index, int* errorRea
155166
}
156167
#endif /* NOTIFY_CAPI_IMPLEMENT_GET_CAPI */
157168

169+
#ifdef __cplusplus
170+
} /* extern "C" */
171+
#endif
172+
158173
#endif /* NOTIFY_CAPI_H */

0 commit comments

Comments
 (0)