#include "main.h"
#include <lua.h>
#include <lauxlib.h>
#include "sound.h"

int lib_music(lua_State *L)
{
	if (lua_isnil(L,1)) {
		Snd_StopMusic();
		return 0;
	}
	const char *name = luaL_checkstring(L,1);
	bool loop = lua_toboolean(L,2);
	Snd_PlayMusic(name,loop);
	return 0;
}

int lib_noise(lua_State *L)
{
	if (lua_isnil(L,1)) {
		Snd_StopNoise();
		return 0;
	}
	bool sine = lua_toboolean(L,1);
	Snd_PlayNoise(sine);
	return 0;
}

static luaL_Reg lib[] = {
	{"music",lib_music},
	{"noise",lib_noise},
	{NULL,NULL}
};

void agllib_snd(lua_State *L, bool client)
{
	luaL_register(L,"snd",lib);
	lua_pop(L,1);
}
