-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathplumbmsg.c
More file actions
92 lines (77 loc) · 1.65 KB
/
Copy pathplumbmsg.c
File metadata and controls
92 lines (77 loc) · 1.65 KB
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
#include "a.h"
#define PLUMBMSG "Plumbmsg"
typedef struct LPlumbmsg LPlumbmsg;
struct LPlumbmsg
{
Plumbmsg *m;
};
void
pushplumbmsg(lua_State *L, Plumbmsg *m)
{
LPlumbmsg *l;
l = (LPlumbmsg*)lua_newuserdata(L, sizeof(LPlumbmsg));
luaL_getmetatable(L, PLUMBMSG);
lua_setmetatable(L, -2);
l->m = m;
}
Plumbmsg*
checkplumbmsg(lua_State *L, int index)
{
LPlumbmsg *l;
l = (LPlumbmsg*)luaL_checkudata(L, index, PLUMBMSG);
luaL_argcheck(L, l != NULL, index, "Plumbmsg expected");
return l->m;
}
static int
plumbmsg__gc(lua_State *L)
{
LPlumbmsg *l;
l = (LPlumbmsg*)luaL_checkudata(L, 1, PLUMBMSG);
luaL_argcheck(L, l != NULL, 1, "Plumbmsg expected");
plumbfree(l->m);
free(l);
lua_pushboolean(L, 1);
return 1;
}
static int
plumbmsg__tostring(lua_State *L)
{
void *p;
p = lua_touserdata(L, 1);
lua_pushfstring(L, "plumbmsg: %p", p);
return 1;
}
static int
plumbmsg__index(lua_State *L)
{
Plumbmsg *m;
const char *s;
m = checkplumbmsg(L, 1);
s = luaL_checkstring(L, 2);
if(strncmp(s, "src", 3) == 0)
lua_pushstring(L, m->src);
else if(strncmp(s, "dst", 3) == 0)
lua_pushstring(L, m->dst);
else if(strncmp(s, "wdir", 4) == 0)
lua_pushstring(L, m->wdir);
else if(strncmp(s, "type", 4) == 0)
lua_pushstring(L, m->type);
else if(strncmp(s, "data", 4) == 0)
lua_pushstring(L, m->data);
else if(strncmp(s, "attr", 4) == 0)
pushplumbattr(L, m->attr);
else
return 0;
return 1;
}
static const struct luaL_Reg plumbmsg_funcs[] = {
{ "__gc", plumbmsg__gc },
{ "__tostring", plumbmsg__tostring },
{ "__index", plumbmsg__index },
{ NULL, NULL },
};
void
registerplumbmsgmeta(lua_State *L)
{
createmetatable(L, PLUMBMSG, plumbmsg_funcs);
}