are really equal */
static int lua_storage_mailbox_eq(lua_State *L)
{
- struct dlua_script *script = dlua_script_from_state(L);
DLUA_REQUIRE_ARGS(L, 2);
struct mailbox *mbox = lua_check_storage_mailbox(L, 1);
struct mailbox *mbox2 = lua_check_storage_mailbox(L, 2);
- lua_pushboolean(script->L, DLUA_MAILBOX_EQUALS(mbox, mbox2));
+ lua_pushboolean(L, DLUA_MAILBOX_EQUALS(mbox, mbox2));
return 1;
}
/* these compare based to mailbox vname */
static int lua_storage_mailbox_lt(lua_State *L)
{
- struct dlua_script *script = dlua_script_from_state(L);
DLUA_REQUIRE_ARGS(L, 2);
bool res = lua_storage_cmp(L) <= 0;
- lua_pushboolean(script->L, res);
+ lua_pushboolean(L, res);
return 1;
}
static int lua_storage_mailbox_le(lua_State *L)
{
- struct dlua_script *script = dlua_script_from_state(L);
DLUA_REQUIRE_ARGS(L, 2);
bool res = lua_storage_cmp(L) < 0;
- lua_pushboolean(script->L, res);
+ lua_pushboolean(L, res);
return 1;
}
static int lua_storage_mailbox_unref(lua_State *L)
{
- struct dlua_script *script = dlua_script_from_state(L);
DLUA_REQUIRE_ARGS(L, 1);
/* fetch item from table */
- lua_pushliteral(script->L, "item");
- lua_rawget(script->L, 1);
- struct mailbox **mbox = lua_touserdata(script->L, -1);
+ lua_pushliteral(L, "item");
+ lua_rawget(L, 1);
+ struct mailbox **mbox = lua_touserdata(L, -1);
if (*mbox != NULL)
mailbox_free(mbox);
*mbox = NULL;
- lua_pop(script->L, 1);
+ lua_pop(L, 1);
return 0;
}
static int lua_storage_mailbox_gc(lua_State *L)
{
- struct dlua_script *script = dlua_script_from_state(L);
- struct mailbox **mbox = lua_touserdata(script->L, 1);
+ struct mailbox **mbox = lua_touserdata(L, 1);
if (*mbox != NULL)
mailbox_free(mbox);
static int lua_storage_mailbox_open(lua_State *L)
{
- struct dlua_script *script = dlua_script_from_state(L);
DLUA_REQUIRE_ARGS(L, 1);
struct mailbox *mbox = lua_check_storage_mailbox(L, 1);
/* try to open the box */
if (mailbox_open(mbox) < 0) {
- return luaL_error(script->L, "mailbox_open(%s) failed: %s",
+ return luaL_error(L, "mailbox_open(%s) failed: %s",
mailbox_get_vname(mbox),
mailbox_get_last_error(mbox, NULL));
}
static int lua_storage_mailbox_sync(lua_State *L)
{
- struct dlua_script *script = dlua_script_from_state(L);
DLUA_REQUIRE_ARGS_IN(L, 1, 2);
struct mailbox *mbox = lua_check_storage_mailbox(L, 1);
enum mailbox_sync_flags flags = 0;
- if (lua_gettop(script->L) >= 2)
- flags = luaL_checkinteger(script->L, 2);
+ if (lua_gettop(L) >= 2)
+ flags = luaL_checkinteger(L, 2);
if (mailbox_sync(mbox, flags) < 0) {
const char *error = mailbox_get_last_error(mbox, NULL);
- return luaL_error(script->L, "mailbox_sync(%s) failed: %s",
+ return luaL_error(L, "mailbox_sync(%s) failed: %s",
mailbox_get_vname(mbox), error);
}
{
struct mailbox_status status;
const char *const *keyword;
- struct dlua_script *script = dlua_script_from_state(L);
struct mailbox *mbox = lua_check_storage_mailbox(L, 1);
/* get items as list of parameters */
enum mailbox_status_items items = 0;
- if (lua_gettop(script->L) < 2)
- return luaL_error(script->L, "expecting at least 1 parameter");
- for(int i = 2; i <= lua_gettop(script->L); i++)
- items |= (unsigned int)luaL_checkinteger(script->L, i);
+ if (lua_gettop(L) < 2)
+ return luaL_error(L, "expecting at least 1 parameter");
+ for(int i = 2; i <= lua_gettop(L); i++)
+ items |= (unsigned int)luaL_checkinteger(L, i);
i_zero(&status);
if (mailbox_get_status(mbox, items, &status) < 0) {
const char *error = mailbox_get_last_error(mbox, NULL);
- return luaL_error(script->L, "mailbox_get_status(%s, %u) failed: %s",
+ return luaL_error(L, "mailbox_get_status(%s, %u) failed: %s",
mbox, items, error);
}
/* returns a table */
- lua_createtable(script->L, 0, 20);
+ lua_createtable(L, 0, 20);
- lua_pushstring(script->L, mailbox_get_vname(mbox));
- lua_setfield(script->L, -2, "mailbox");
+ lua_pushstring(L, mailbox_get_vname(mbox));
+ lua_setfield(L, -2, "mailbox");
#undef LUA_TABLE_SETNUMBER
#define LUA_TABLE_SETNUMBER(field) \
- lua_pushnumber(script->L, status.field); \
- lua_setfield(script->L, -2, #field);
+ lua_pushnumber(L, status.field); \
+ lua_setfield(L, -2, #field);
#undef LUA_TABLE_SETBOOL
#define LUA_TABLE_SETBOOL(field) \
- lua_pushboolean(script->L, status.field); \
- lua_setfield(script->L, -2, #field);
+ lua_pushboolean(L, status.field); \
+ lua_setfield(L, -2, #field);
LUA_TABLE_SETNUMBER(messages);
LUA_TABLE_SETNUMBER(recent);
if (status.keywords != NULL && array_is_created(status.keywords)) {
int i = 1;
- lua_createtable(script->L, array_count(status.keywords), 0);
+ lua_createtable(L, array_count(status.keywords), 0);
array_foreach(status.keywords, keyword) {
- lua_pushstring(script->L, *keyword);
- lua_rawseti(script->L, -2, i++);
+ lua_pushstring(L, *keyword);
+ lua_rawseti(L, -2, i++);
}
- lua_setfield(script->L, -2, "keywords");
+ lua_setfield(L, -2, "keywords");
}
return 1;
static int lua_storage_mailbox_metadata_get(lua_State *L)
{
- struct dlua_script *script = dlua_script_from_state(L);
- if (lua_gettop(script->L) < 2)
- return luaL_error(script->L, "expecting at least 1 parameter");
+ if (lua_gettop(L) < 2)
+ return luaL_error(L, "expecting at least 1 parameter");
struct mailbox *mbox = lua_check_storage_mailbox(L, 1);
const char *value, *error;
size_t value_len;
- int ret, i, top = lua_gettop(script->L);
+ int ret, i, top = lua_gettop(L);
ret = 0;
for(i = 2; i <= top; i++) {
- const char *key = lua_tostring(script->L, i);
+ const char *key = lua_tostring(L, i);
if (key == NULL) {
ret = -1;
error = t_strdup_printf("expected string at #%d", i);
&value_len, &error)) < 0) {
break;
} else if (ret == 0) {
- lua_pushnil(script->L);
+ lua_pushnil(L);
} else {
- lua_pushlstring(script->L, value, value_len);
+ lua_pushlstring(L, value, value_len);
}
}
if (ret < 0)
- return luaL_error(script->L, "%s", error);
+ return luaL_error(L, "%s", error);
/* return number of pushed items */
i_assert(i>=2);
static int lua_storage_mailbox_metadata_set(lua_State *L)
{
- struct dlua_script *script = dlua_script_from_state(L);
DLUA_REQUIRE_ARGS(L, 3);
struct mailbox *mbox = lua_check_storage_mailbox(L, 1);
- const char *key = luaL_checkstring(script->L, 2);
+ const char *key = luaL_checkstring(L, 2);
const char *value, *error;
size_t value_len;
- value = lua_tolstring(script->L, 3, &value_len);
+ value = lua_tolstring(L, 3, &value_len);
if (lua_storage_mailbox_attribute_set(mbox, key, value, value_len, &error) < 0)
- return luaL_error(script->L,
+ return luaL_error(L,
t_strdup_printf("Cannot set attribute: %s", error));
return 0;
static int lua_storage_mailbox_metadata_unset(lua_State *L)
{
- struct dlua_script *script = dlua_script_from_state(L);
DLUA_REQUIRE_ARGS(L, 2);
struct mailbox *mbox = lua_check_storage_mailbox(L, 1);
- const char *key = luaL_checkstring(script->L, 2);
+ const char *key = luaL_checkstring(L, 2);
const char *error;
if (lua_storage_mailbox_attribute_set(mbox, key, NULL, 0, &error) < 0)
- return luaL_error(script->L,
+ return luaL_error(L,
t_strdup_printf("Cannot unset attribute: %s", error));
return 0;
static int lua_storage_mailbox_metadata_list(lua_State *L)
{
- struct dlua_script *script = dlua_script_from_state(L);
- if (lua_gettop(script->L) < 2)
- return luaL_error(script->L, "expecting at least 1 parameter");
+ if (lua_gettop(L) < 2)
+ return luaL_error(L, "expecting at least 1 parameter");
struct mailbox *mbox = lua_check_storage_mailbox(L, 1);
const struct lua_storage_keyvalue *item;
const char *error;
t_array_init(&items, 1);
ret = 0;
- for(i = 2; i <= lua_gettop(script->L); i++) {
- const char *key = lua_tostring(script->L, i);
+ for(i = 2; i <= lua_gettop(L); i++) {
+ const char *key = lua_tostring(L, i);
if (key == NULL) {
ret = -1;
}
if (ret == 0) {
- lua_createtable(script->L, 0, array_count(&items));
+ lua_createtable(L, 0, array_count(&items));
array_foreach(&items, item) {
/* push value */
- lua_pushlstring(script->L, item->value,
+ lua_pushlstring(L, item->value,
item->value_len);
/* set field */
- lua_setfield(script->L, -2, item->key);
+ lua_setfield(L, -2, item->key);
}
}
} T_END;
if (ret == -1)
- return luaL_error(script->L, "%s", error);
+ return luaL_error(L, "%s", error);
/* stack should have table with items */
return 1;