summaryrefslogtreecommitdiff
path: root/plugins/MirLua/src/m_sounds.cpp
blob: 62ae176b67a0d1539cfe59dbde28c46bb5fa77a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include "stdafx.h"

static int lua_AddSound(lua_State *L)
{
	ptrA name(mir_utf8decodeA(luaL_checkstring(L, 1)));
	ptrW description(mir_utf8decodeW(luaL_checkstring(L, 2)));
	ptrW section(mir_utf8decodeW(luaL_optstring(L, 3, MODULE)));
	ptrW filePath(mir_utf8decodeW(lua_tostring(L, 4)));

	int res = Skin_AddSound(name, section, description, filePath, CMLuaEnvironment::GetEnvironmentId(L));
	lua_pushboolean(L, res == 0);

	return 1;
}

static int lua_PlaySound(lua_State *L)
{
	const char *name = luaL_checkstring(L, 1);

	INT_PTR res = Skin_PlaySound(name);
	lua_pushboolean(L, res == 0);

	return 1;
}

static int lua_PlayFile(lua_State *L)
{
	ptrW filePath(mir_utf8decodeW(luaL_checkstring(L, 1)));

	INT_PTR res = Skin_PlaySoundFile(filePath);
	lua_pushboolean(L, res == 0);

	return 1;
}

static luaL_Reg soundApi[] =
{
	{ "AddSound", lua_AddSound },

	{ "PlaySound", lua_PlaySound },
	{ "PlayFile", lua_PlayFile },

	{ nullptr, nullptr }
};

LUAMOD_API int luaopen_m_sounds(lua_State *L)
{
	luaL_newlib(L, soundApi);

	return 1;
}