doap: Add XEP-0288
[prosody.git] / util-src / table.c
blob9a9553fce84dfaf348261eae167d490cd96c4c49
1 #include <lua.h>
2 #include <lauxlib.h>
4 static int Lcreate_table(lua_State *L) {
5 lua_createtable(L, luaL_checkinteger(L, 1), luaL_checkinteger(L, 2));
6 return 1;
9 static int Lpack(lua_State *L) {
10 unsigned int n_args = lua_gettop(L);
11 lua_createtable(L, n_args, 1);
12 lua_insert(L, 1);
14 for(int arg = n_args; arg >= 1; arg--) {
15 lua_rawseti(L, 1, arg);
18 lua_pushinteger(L, n_args);
19 lua_setfield(L, -2, "n");
20 return 1;
23 int luaopen_util_table(lua_State *L) {
24 #if (LUA_VERSION_NUM > 501)
25 luaL_checkversion(L);
26 #endif
27 lua_createtable(L, 0, 2);
28 lua_pushcfunction(L, Lcreate_table);
29 lua_setfield(L, -2, "create");
30 lua_pushcfunction(L, Lpack);
31 lua_setfield(L, -2, "pack");
32 return 1;