/* Close the cursor on top of the stack. Return 1  */
static int cur_close(lua_State *L)
/* Close the cursor on top of the stack. Return 1  */
static int cur_close(lua_State *L)
{
	conn_data *conn;
	cur_data *cur = (cur_data *)luaL_checkudata(L, 1, LUASQL_CURSOR_SQLITE);
	luaL_argcheck(L, cur != NULL, 1, LUASQL_PREFIX"cursor expected");
	if (cur->closed) {
		lua_pushboolean(L, 0);
		return 1;
	}
	cur->closed = 1;
	sqlite3_finalize(cur->sql_vm);
	lua_rawgeti (L, LUA_REGISTRYINDEX, cur->conn);
	conn = lua_touserdata (L, -1);
	conn->cur_counter--;
	luaL_unref(L, LUA_REGISTRYINDEX, cur->conn);
	luaL_unref(L, LUA_REGISTRYINDEX, cur->colnames);
	luaL_unref(L, LUA_REGISTRYINDEX, cur->coltypes);
	lua_pushboolean(L, 1);
	return 1;
}