-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmsgpack.c
More file actions
33 lines (28 loc) · 798 Bytes
/
msgpack.c
File metadata and controls
33 lines (28 loc) · 798 Bytes
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
#include "msgpack.h"
LUAMOD_API int luaopen_lmsgpack(lua_State *L) {
luaL_checkversion(L);
if (USE_MSGPACK_MAX_STACK > LUA_MINSTACK)
lua_checkstack(L, USE_MSGPACK_MAX_STACK);
/* 元表 */
luaL_newmetatable(L, "lua_Table");
luaL_newmetatable(L, "lua_List");
luaL_Reg msgpack_libs[] = {
{"encode", lmsgpack_encode},
{"decode", lmsgpack_decode},
{"pack", lmsgpack_encode},
{"unpack", lmsgpack_decode},
{NULL, NULL}
};
luaL_newlib(L, msgpack_libs);
/* 关联`empty_array`表 */
lua_newtable(L);
luaL_setmetatable(L, "lua_List");
lua_setfield (L, -2, "empty_array");
/* 设置版本号 */
lua_pushnumber(L, 0.1);
lua_setfield (L, -2, "version");
return 1;
}
LUAMOD_API int luaopen_lmsgpack_safe(lua_State *L) {
return luaopen_lmsgpack(L);
}