Mercurial > prosody-hg
comparison util-src/table.c @ 7892:f00943bbf84f
Merge 0.10->trunk
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Tue, 14 Feb 2017 23:42:11 +0100 |
| parents | b8d694646597 |
| children | 582bfb39337f |
comparison
equal
deleted
inserted
replaced
| 7887:93fd15b5ec1b | 7892:f00943bbf84f |
|---|---|
| 1 #include <lua.h> | 1 #include <lua.h> |
| 2 #include <lauxlib.h> | 2 #include <lauxlib.h> |
| 3 | 3 |
| 4 static int Lcreate_table(lua_State* L) { | 4 static int Lcreate_table(lua_State *L) { |
| 5 lua_createtable(L, luaL_checkinteger(L, 1), luaL_checkinteger(L, 2)); | 5 lua_createtable(L, luaL_checkinteger(L, 1), luaL_checkinteger(L, 2)); |
| 6 return 1; | 6 return 1; |
| 7 } | 7 } |
| 8 | 8 |
| 9 static int Lpack(lua_State* L) { | 9 static int Lpack(lua_State *L) { |
| 10 int arg; | 10 int arg; |
| 11 unsigned int n_args = lua_gettop(L); | 11 unsigned int n_args = lua_gettop(L); |
| 12 lua_createtable(L, n_args, 1); | 12 lua_createtable(L, n_args, 1); |
| 13 lua_insert(L, 1); | 13 lua_insert(L, 1); |
| 14 | |
| 14 for(arg = n_args; arg >= 1; arg--) { | 15 for(arg = n_args; arg >= 1; arg--) { |
| 15 lua_rawseti(L, 1, arg); | 16 lua_rawseti(L, 1, arg); |
| 16 } | 17 } |
| 18 | |
| 17 lua_pushinteger(L, n_args); | 19 lua_pushinteger(L, n_args); |
| 18 lua_setfield(L, -2, "n"); | 20 lua_setfield(L, -2, "n"); |
| 19 return 1; | 21 return 1; |
| 20 } | 22 } |
| 21 | 23 |
| 22 int luaopen_util_table(lua_State* L) { | 24 int luaopen_util_table(lua_State *L) { |
| 23 #if (LUA_VERSION_NUM > 501) | 25 #if (LUA_VERSION_NUM > 501) |
| 24 luaL_checkversion(L); | 26 luaL_checkversion(L); |
| 25 #endif | 27 #endif |
| 26 lua_newtable(L); | 28 lua_newtable(L); |
| 27 lua_pushcfunction(L, Lcreate_table); | 29 lua_pushcfunction(L, Lcreate_table); |
