<commit_before>/* vim: set cino= fo=croql sw=8 ts=8 sts=0 noet autoindent cindent fdm=syntax : */

/* libmpdclient Lua bindings
   (c) 2009 <NAME> <<EMAIL>>
   (c) 2009 <NAME> <<EMAIL>>

   Redistribution and use in source and binary forms, with or without
   modification, are permitted provided that the following conditions
   are met:

   - Redistributions of source code must retain the above copyright
   notice, this list of conditions and the following disclaimer.

   - Redistributions in binary form must reproduce the above copyright
   notice, this list of conditions and the following disclaimer in the
   documentation and/or other materials provided with the distribution.

   - Neither the name of the Music Player Daemon nor the names of its
   contributors may be used to endorse or promote products derived from
   this software without specific prior written permission.

   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
   ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
   A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR
   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
   EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
   PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
   PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
   LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include <assert.h>
#include <stdlib.h>
#include <string.h>

#include <lua.h>
#include <lauxlib.h>

#include <mpd/connection.h>
#include <mpd/capabilities.h>
#include <mpd/entity.h>
#include <mpd/idle.h>
#include <mpd/list.h>
#include <mpd/mixer.h>
#include <mpd/output.h>
#include <mpd/pair.h>
#include <mpd/response.h>
#include <mpd/status.h>

#include "globals.h"

/* connection.h */
static int lmpdconn_gc(lua_State *L)
{
	struct mpd_connection **conn;

	conn = luaL_checkudata(L, 1, MPD_CONNECTION_T);

	if (*conn != NULL)
		mpd_connection_free(*conn);
	*conn = NULL;

	return 0;
}

static int lmpdconn_set_timeout(lua_State *L)
{
	struct mpd_connection **conn;
	double timeout;

	conn = luaL_checkudata(L, 1, MPD_CONNECTION_T);
	timeout = luaL_checknumber(L, 2);

	assert(*conn != NULL);

	mpd_connection_set_timeout(*conn, timeout);
	return 0;
}

static int lmpdconn_get_fd(lua_State *L)
{
	struct mpd_connection **conn;

	conn = luaL_checkudata(L, 1, MPD_CONNECTION_T);

	assert(*conn != NULL);

	mpd_connection_get_fd(*conn);

	lua_pushinteger(L, mpd_connection_get_fd(*conn));
	return 1;
}

static int lmpdconn_get_error(lua_State *L)
{
	struct mpd_connection **conn;

	conn = luaL_checkudata(L, 1, MPD_CONNECTION_T);

	assert(*conn != NULL);

	lua_pushinteger(L, mpd_get_error(*conn));

	return 1;
}

static int lmpdconn_get_error_message(lua_State *L)
{
	struct mpd_connection **conn;

	conn = luaL_checkudata(L, 1, MPD_CONNECTION_T);

	assert(*conn != NULL);

	lua_pushstring(L, mpd_get_error_message(*conn));

	return 1;
}

static int lmpdconn_get_server_error(lua_State *L)
{
	struct mpd_connection **conn;

	conn = luaL_checkudata(L, 1, MPD_CONNECTION_T);

	assert(*conn != NULL);

	lua_pushinteger(L, mpd_get_server_error(*conn));

	return 1;
}

static int lmpdconn_clear_error(lua_State *L)
{
	struct mpd_connection **conn;

	conn = luaL_checkudata(L, 1, MPD_CONNECTION_T);

	assert(*conn != NULL);

	lua_pushboolean(L, mpd_clear_error(*conn));

	return 1;
}

static int lmpdconn_get_server_version(lua_State *L)
{
	struct mpd_connection **conn;

	conn = luaL_checkudata(L, 1, MPD_CONNECTION_T);

	assert(*conn != NULL);

	lua_pushinteger(L, mpd_get_server_version(*conn)[0]);
	lua_pushinteger(L, mpd_get_server_version(*conn)[1]);
	lua_pushinteger(L, mpd_get_server_version(*conn)[2]);

	return 3;
}

static int lmpdconn_cmp_server_version(lua_State *L)
{
	struct mpd_connection **conn;
	lua_Integer major, minor, patch;

	conn = luaL_checkudata(L, 1, MPD_CONNECTION_T);
	major = luaL_checkinteger(L, 2);
	minor = luaL_checkinteger(L, 3);
	patch = luaL_checkinteger(L, 4);

	assert(*conn != NULL);

	lua_pushinteger(L, mpd_cmp_server_version(*conn, major, minor, patch));

	return 1;
}

/* capabilities.h */
static int lmpdconn_send_allowed_commands(lua_State *L)
{
	struct mpd_connection **conn;

	conn = luaL_checkudata(L, 1, MPD_CONNECTION_T);

	assert(*conn != NULL);

	lua_pushboolean(L, mpd_send_allowed_commands(*conn));

	return 1;
}

static int lmpdconn_send_disallowed_commands(lua_State *L)
{
	struct mpd_connection **conn;

	conn = luaL_checkudata(L, 1, MPD_CONNECTION_T);
<commit_msg>connection was inserted into some function names in connection.h<commit_after>/* vim: set cino= fo=croql sw=8 ts=8 sts=0 noet autoindent cindent fdm=syntax : */

/* libmpdclient Lua bindings
   (c) 2009 <NAME> <<EMAIL>>
   (c) 2009 <NAME> <<EMAIL>>

   Redistribution and use in source and binary forms, with or without
   modification, are permitted provided that the following conditions
   are met:

   - Redistributions of source code must retain the above copyright
   notice, this list of conditions and the following disclaimer.

   - Redistributions in binary form must reproduce the above copyright
   notice, this list of conditions and the following disclaimer in the
   documentation and/or other materials provided with the distribution.

   - Neither the name of the Music Player Daemon nor the names of its
   contributors may be used to endorse or promote products derived from
   this software without specific prior written permission.

   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
   ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
   A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR
   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
   EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
   PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
   PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
   LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include <assert.h>
#include <stdlib.h>
#include <string.h>

#include <lua.h>
#include <lauxlib.h>

#include <mpd/connection.h>
#include <mpd/capabilities.h>
#include <mpd/entity.h>
#include <mpd/idle.h>
#include <mpd/list.h>
#include <mpd/mixer.h>
#include <mpd/output.h>
#include <mpd/pair.h>
#include <mpd/response.h>
#include <mpd/status.h>

#include "globals.h"

/* connection.h */
static int lmpdconn_gc(lua_State *L)
{
	struct mpd_connection **conn;

	conn = luaL_checkudata(L, 1, MPD_CONNECTION_T);

	if (*conn != NULL)
		mpd_connection_free(*conn);
	*conn = NULL;

	return 0;
}

static int lmpdconn_set_timeout(lua_State *L)
{
	struct mpd_connection **conn;
	double timeout;

	conn = luaL_checkudata(L, 1, MPD_CONNECTION_T);
	timeout = luaL_checknumber(L, 2);

	assert(*conn != NULL);

	mpd_connection_set_timeout(*conn, timeout);
	return 0;
}

static int lmpdconn_get_fd(lua_State *L)
{
	struct mpd_connection **conn;

	conn = luaL_checkudata(L, 1, MPD_CONNECTION_T);

	assert(*conn != NULL);

	mpd_connection_get_fd(*conn);

	lua_pushinteger(L, mpd_connection_get_fd(*conn));
	return 1;
}

static int lmpdconn_get_error(lua_State *L)
{
	struct mpd_connection **conn;

	conn = luaL_checkudata(L, 1, MPD_CONNECTION_T);

	assert(*conn != NULL);

	lua_pushinteger(L, mpd_connection_get_error(*conn));

	return 1;
}

static int lmpdconn_get_error_message(lua_State *L)
{
	struct mpd_connection **conn;

	conn = luaL_checkudata(L, 1, MPD_CONNECTION_T);

	assert(*conn != NULL);

	lua_pushstring(L, mpd_connection_get_error_message(*conn));

	return 1;
}

static int lmpdconn_get_server_error(lua_State *L)
{
	struct mpd_connection **conn;

	conn = luaL_checkudata(L, 1, MPD_CONNECTION_T);

	assert(*conn != NULL);

	lua_pushinteger(L, mpd_connection_get_server_error(*conn));

	return 1;
}

static int lmpdconn_clear_error(lua_State *L)
{
	struct mpd_connection **conn;

	conn = luaL_checkudata(L, 1, MPD_CONNECTION_T);

	assert(*conn != NULL);

	lua_pushboolean(L, mpd_connection_clear_error(*conn));

	return 1;
}

static int lmpdconn_get_server_version(lua_State *L)
{
	struct mpd_connection **conn;

	conn = luaL_checkudata(L, 1, MPD_CONNECTION_T);

	assert(*conn != NULL);

	lua_pushinteger(L, mpd_connection_get_server_version(*conn)[0]);
	lua_pushinteger(L, mpd_connection_get_server_version(*conn)[1]);
	lua_pushinteger(L, mpd_connection_get_server_version(*conn)[2]);

	return 3;
}

static int lmpdconn_cmp_server_version(lua_State *L)
{
	struct mpd_connection **conn;
	lua_Integer major, minor, patch;

	conn = luaL_checkudata(L, 1, MPD_CONNECTION_T);
	major = luaL_checkinteger(L, 2);
	minor = luaL_checkinteger(L, 3);
	patch = luaL_checkinteger(L, 4);

	assert(*conn != NULL);

	lua_pushinteger(L, mpd_connection_cmp_server_version(*conn, major, minor, patch));

	return 1;
}

/* capabilities.h */
static int lmpdconn_send_allowed_commands(lua_State *L)
{
	struct mpd_connection **conn;

	conn = luaL_checkudata(L, 1, MPD_CONNECTION_T);

	assert(*conn != NULL);

	lua_pushboolean(L, mpd_send_allowed_commands(*conn));

	return 1;
}

static int lmpdconn_send_disallowed_commands(lua_State *L)
{
	struct mpd_connection **conn;

	conn = luaL_checkudata(L, 1, MPD_CONNECTION_T);

{'fraction_non_alphanumeric': 0.10282485875706214, 'fraction_numerical': 0.008012326656394453, 'mean_word_length': 5.217113665389528, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2922416', 'n_tokens_mistral': 3623, 'n_tokens_neox': 3358, 'n_words': 966}