314bc5df
zhengshouren
提交服务器初始代码
|
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
|
lua_createtable(L, 0, 3); 创建大小为3的table
lua_pushcfunction(L, lcopy); 将lcopy压栈
lua_setfield(L, -2, "copy");
{
copy = lcopy,
}
====================================================================
lua_createtable(L, 0, 2); 创建大小为2的table
lua_pushcfunction(L, ldeletewriter),
lua_setfield(L, -2, "__gc");
lua_pushcfunction(L, lupdate),
lua_setfield(L, -2, "__call");
table = {
__gc = ldeletewriter,
__call = lupdate,
}
luaL_Reg writer[] = {
{ "new", lnewwriter },
{ NULL, NULL },
};
luaL_setfuncs(L, writer, 1);
将 writer 压入栈顶,并将table作为上值
====================================================================
lua_createtable(L, 0, 2);
lua_pushcfunction(L, ldeletereader),
lua_setfield(L, -2, "__gc");
lua_pushcfunction(L, lread),
lua_setfield(L, -2, "__call");
table = {
__gc = ldeletereader,
__call = lread,
}
luaL_Reg reader[] = {
{ "newcopy", lnewreader },
{ NULL, NULL },
};
luaL_setfuncs(L, reader, 1);
将 reader 压入栈顶,并将table作为上值
====================================================================
{
copy = lcopy,
writer = ...,
reader = ...,
}
====================================================================
luaL_Reg m[] = {
{ "pop", lpop },
{ "push", lpush },
{ "size", lsize },
{ NULL, NULL },
};
luaL_newmetatable(L, "dangge.deque"); 创建一个meta表并压栈
lua_pushvalue(L, -1); 复制一个meta表
lua_setfield(L, -2, "__index"); meta = {__index = meta}
luaL_setfuncs(L, m, 0); meta = {pop = lpop, push = lpush, size = lsize}
|