args = g_slice_alloc ((top + 1) * sizeof (gchar *));
arglens = g_slice_alloc ((top + 1) * sizeof (gsize));
- lua_pushnil (L);
arglens[0] = strlen (cmd);
args[0] = g_slice_alloc (arglens[0]);
memcpy (args[0], cmd, arglens[0]);
top = 1;
+ lua_pushnil (L);
while (lua_next (L, -2) != 0) {
if (lua_isstring (L, -1)) {
args = g_slice_alloc (sizeof (gchar *));
arglens = g_slice_alloc (sizeof (gsize));
- lua_pushnil (L);
arglens[0] = strlen (cmd);
args[0] = g_slice_alloc (arglens[0]);
memcpy (args[0], cmd, arglens[0]);
}
}
- lua_pushboolean (L, 1);
+ lua_pushboolean (L, true);
return 1;
}
return 0;
}
else {
+ if (!lua_checkstack (L, (ctx->cmds_pending * 2) + 1)) {
+ return luaL_error (L, "cannot resiz stack to fit %d commands",
+ ctx->cmds_pending);
+ }
for (i = 0; i < ctx->cmds_pending; i ++) {
ret = redisGetReply (ctx->d.sync, (void **)&r);
}
else {
lua_pushboolean (L, FALSE);
- lua_pushstring (L, r->str);
+ lua_pushlstring (L, r->str, r->len);
}
freeReplyObject (r);
}
}
}
- return 0;
+ lua_pushnil (L);
+
+ return 1;
}
/***
if (sqlite3_prepare_v2 (db, query, -1, &stmt, NULL) != SQLITE_OK) {
msg_err ("cannot prepare query %s: %s", query, sqlite3_errmsg (db));
lua_pushstring (L, sqlite3_errmsg (db));
- lua_error (L);
+ return lua_error (L);
}
else {
top = lua_gettop (L);
const ucl_object_t *res, const gchar *script)
{
lua_State *L = pL;
- gint err_idx, cb_idx, i, ret;
+ gint err_idx, i, ret;
GString *tb;
g_assert (script != NULL);
return FALSE;
}
else {
- if (lua_type (L, -1) == LUA_TFUNCTION) {
- cb_idx = luaL_ref (L, LUA_REGISTRYINDEX);
- }
- else {
+ if (lua_type (L, -1) != LUA_TFUNCTION) {
msg_err ("lua script must return "
"function and not %s",
lua_typename (L,
lua_type (L, -1)));
+ lua_settop (L, 0);
+
return FALSE;
}
}
err_idx = lua_gettop (L);
/* Push function */
- lua_rawgeti (L, LUA_REGISTRYINDEX, cb_idx);
+ lua_pushvalue (L, -2);
/* Push argv */
lua_newtable (L);
g_string_free (tb, TRUE);
}
- lua_pop (L, 2);
+ lua_settop (L, 0);
return FALSE;
}
/* error function */
- lua_pop (L, 1);
-
- luaL_unref (L, LUA_REGISTRYINDEX, cb_idx);
+ lua_settop (L, 0);
return TRUE;
}