diff options
author | PilzAdam <pilzadam@minetest.net> | 2013-07-28 23:14:42 +0200 |
---|---|---|
committer | PilzAdam <pilzadam@minetest.net> | 2013-07-28 23:29:03 +0200 |
commit | 4fb4efd8ed54a81ea545e51265f2acdd01654f21 (patch) | |
tree | 4f47e2a94931500675ca11f6b008d4186f4c1b61 /src/guiLuaApi.cpp | |
parent | 174285f29878c7171c84848ae9282a9efa546bd6 (diff) | |
download | minetest-4fb4efd8ed54a81ea545e51265f2acdd01654f21.tar.gz minetest-4fb4efd8ed54a81ea545e51265f2acdd01654f21.tar.bz2 minetest-4fb4efd8ed54a81ea545e51265f2acdd01654f21.zip |
Play sounds/main_menu.ogg in menu
Diffstat (limited to 'src/guiLuaApi.cpp')
-rw-r--r-- | src/guiLuaApi.cpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/guiLuaApi.cpp b/src/guiLuaApi.cpp index b00bb5a84..485cab883 100644 --- a/src/guiLuaApi.cpp +++ b/src/guiLuaApi.cpp @@ -31,6 +31,7 @@ extern "C" { #include "settings.h" #include "filesys.h" #include "convert_json.h" +#include "sound.h" #include "IFileArchive.h" @@ -92,6 +93,8 @@ void guiLuaApi::initialize(lua_State* L,GUIEngine* engine) retval &= API_FCT(download_file); retval &= API_FCT(get_modstore_details); retval &= API_FCT(get_modstore_list); + retval &= API_FCT(sound_play); + retval &= API_FCT(sound_stop); if (!retval) { //TODO show error @@ -1051,6 +1054,49 @@ int guiLuaApi::l_get_version(lua_State *L) { } /******************************************************************************/ +int guiLuaApi::l_sound_play(lua_State *L) { + GUIEngine* engine = get_engine(L); + + SimpleSoundSpec spec; + if(lua_isnil(L, 1)) + { + } else if(lua_istable(L, 1)){ + lua_getfield(L, 1, "name"); + if(lua_isstring(L, -1)){ + size_t len = 0; + spec.name = lua_tolstring(L, -1, &len); + } + lua_pop(L, 1); + + //luaL_checkfloat(L, 1, "gain", spec.gain); + lua_getfield(L, 1, "gain"); + if(lua_isnumber(L, -1)){ + spec.gain = lua_tonumber(L, -1); + } + lua_pop(L, 1); + } else if(lua_isstring(L, 1)){ + spec.name = luaL_checkstring(L, 1); + } + bool looped = lua_toboolean(L, 2); + + u32 handle = engine->playSound(spec, looped); + + lua_pushinteger(L, handle); + + return 1; +} + +/******************************************************************************/ +int guiLuaApi::l_sound_stop(lua_State *L) { + GUIEngine* engine = get_engine(L); + + u32 handle = luaL_checkinteger(L, 1); + engine->stopSound(handle); + + return 1; +} + +/******************************************************************************/ int guiLuaApi::l_download_file(lua_State *L) { GUIEngine* engine = get_engine(L); assert(engine != 0); |