-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathipc.h
149 lines (108 loc) · 3.91 KB
/
ipc.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#ifndef IPC_H_
#define IPC_H_
#include <stddef.h>
#include <stdio.h>
#include <lua.h>
#include <lauxlib.h>
#ifndef IPC_LOCAL
/* emulate CLANG feature checking on other compilers */
# ifndef __has_attribute
# define __has_attribute( _x ) 0
# endif
# if !defined( _WIN32 ) && !defined( __CYGWIN__ ) && \
((defined( __GNUC__ ) && __GNUC__ >= 4 ) || \
__has_attribute( __visibility__ ))
# define IPC_LOCAL __attribute__((__visibility__("hidden")))
# else
# define IPC_LOCAL
# endif
#endif
#ifndef IPC_API
# ifdef _WIN32
# define IPC_API __declspec(dllexport)
# else
# define IPC_API extern
# endif
#endif
/* maximum expected length of error messages */
#define IPC_MAXERRMSG 200
#ifndef NDEBUG
# if (defined( __STDC_VERSION__ ) && __STDC_VERSION__ >= 199901L) || \
defined( __GNUC__ ) || defined( __clang__ )
# define IPC_ERR( code ) (ipc_err( __FILE__, __LINE__, __func__, (int)(code) ))
# elif defined( _MSC_VER ) && _MSC_VER >= 1100L
# define IPC_ERR( code ) (ipc_err( __FILE__, __LINE__, __FUNCTION__, (int)(code) ))
# else
# define IPC_ERR( code ) (ipc_err( __FILE__, __LINE__, NULL, (int)(code) ))
# endif
#else
# define IPC_ERR( code ) ((int)(code))
#endif
#define IPC_NOTIMPLEMENTED( L ) \
luaL_error( L, "module '%s' not implemented on this platform", \
lua_tostring( L, 1 ) )
#define IPC_EINTR( _rv, _call ) \
do { \
_rv = _call; \
} while( _rv < 0 && errno == EINTR )
#define IPC_OPTBIGINT( _t, _l, _i, _d ) \
((sizeof( _t ) > sizeof( lua_Integer ) && \
sizeof( lua_Number ) > sizeof( lua_Integer )) \
? (_t)luaL_optnumber( _l, _i, _d ) \
: (_t)luaL_optinteger( _l, _i, _d ))
IPC_LOCAL FILE* ipc_checkfile( lua_State* L, int idx );
IPC_LOCAL FILE* ipc_testfile( lua_State* L, int idx );
IPC_LOCAL int ipc_getuservaluefield( lua_State* L, int idx,
char const* name );
IPC_LOCAL void ipc_setuservaluefield( lua_State* L, int idx,
char const* name );
IPC_LOCAL int ipc_err( char const* file, int line, char const* func,
int code );
/* compatibility functions for older Lua versions */
#if LUA_VERSION_NUM == 501
typedef int lua_KContext;
IPC_LOCAL int ipc_absindex( lua_State* L, int idx );
#define lua_absindex( L, i ) ipc_absindex( L, i )
IPC_LOCAL void* ipc_testudata( lua_State* L, int idx,
char const* name );
#define luaL_testudata( L, i, n ) ipc_testudata( L, i, n )
#define lua_rawlen( L, i ) lua_objlen( L, i )
#define lua_setuservalue( L, i ) lua_setfenv( L, i )
#define lua_getuservalue( L, i ) lua_getfenv( L, i )
#define luaL_newlib( L, r ) \
(lua_newtable( L ), luaL_register( L, NULL, r ))
#define lua_callk( L, na, nr, ctx, cont ) \
((void)ctx, (void)cont, lua_call( L, na, nr ))
#define lua_pcallk( L, na, nr, err, ctx, cont ) \
((void)ctx, (void)cont, lua_pcall( L, na, nr, err ))
#elif LUA_VERSION_NUM == 502
typedef int lua_KContext;
#define LUA_KFUNCTION( _name ) \
static int (_name)( lua_State* L, int status, lua_KContext ctx ); \
static int (_name ## _52)( lua_State* L ) { \
lua_KContext ctx; \
int status = lua_getctx( L, &ctx ); \
return (_name)( L, status, ctx ); \
} \
static int (_name)( lua_State* L, int status, lua_KContext ctx )
#define lua_callk( L, na, nr, ctx, cont ) \
lua_callk( L, na, nr, ctx, cont ## _52 )
#define lua_pcallk( L, na, nr, err, ctx, cont ) \
lua_pcallk( L, na, nr, err, ctx, cont ## _52 )
#ifdef lua_call
# undef lua_call
# define lua_call( L, na, nr ) \
(lua_callk)( L, na, nr, 0, NULL )
#endif
#ifdef lua_pcall
# undef lua_pcall
# define lua_pcall( L, na, nr, err ) \
(lua_pcallk( L, na, nr, err, 0, NULL )
#endif
#endif /* LUA_VERSION_NUM */
#ifndef LUA_KFUNCTION
/* definition for everything except Lua 5.2 */
#define LUA_KFUNCTION( _name ) \
static int (_name)( lua_State* L, int status, lua_KContext ctx )
#endif
#endif /* IPC_H_ */