aboutsummaryrefslogtreecommitdiff
path: root/src/lua/modules/audio/audio.cpp
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2018-10-20 16:18:11 +0800
committerchai <chaifix@163.com>2018-10-20 16:18:11 +0800
commitcf68d9f46da1cf20503a7d738da1f43de916004d (patch)
tree5577e44d926deadb15ef5ca145e705eae14636fe /src/lua/modules/audio/audio.cpp
parente9410bd371fc68169c57d2c52382948a0b083da4 (diff)
*格式化代码
Diffstat (limited to 'src/lua/modules/audio/audio.cpp')
-rw-r--r--src/lua/modules/audio/audio.cpp208
1 files changed, 104 insertions, 104 deletions
diff --git a/src/lua/modules/audio/audio.cpp b/src/lua/modules/audio/audio.cpp
index becde12..8d8bd22 100644
--- a/src/lua/modules/audio/audio.cpp
+++ b/src/lua/modules/audio/audio.cpp
@@ -3,121 +3,121 @@
#include "lua/common/common.h"
#include "libjin/jin.h"
-namespace jin
+namespace JinEngine
{
-namespace lua
-{
+ namespace Lua
+ {
- using namespace JinEngine::Audio;
- using namespace JinEngine::Filesystem;
+ using namespace JinEngine::Audio;
+ using namespace JinEngine::Filesystem;
- typedef SDLAudio Audio;
- typedef SDLSource Source;
+ typedef SDLAudio Audio;
+ typedef SDLSource Source;
- static int l_init(lua_State* L)
- {
- Audio::Setting setting;
- setting.samplerate = 44100;
- setting.samples = 44100;
- if (!Audio::get()->init(&setting))
+ static int l_init(lua_State* L)
{
- luax_error(L, "could not init audio");
- luax_pushboolean(L, false);
+ Audio::Setting setting;
+ setting.samplerate = 44100;
+ setting.samples = 44100;
+ if (!Audio::get()->init(&setting))
+ {
+ luax_error(L, "could not init audio");
+ luax_pushboolean(L, false);
+ return 1;
+ }
+ luax_pushboolean(L, true);
return 1;
}
- luax_pushboolean(L, true);
- return 1;
- }
-
- static int l_play(lua_State* L)
- {
- Audio::get()->play();
- return 0;
- }
-
- static int l_stop(lua_State* L)
- {
- Audio::get()->stop();
- return 0;
- }
-
- static int l_pause(lua_State* L)
- {
- Audio::get()->pause();
- return 0;
- }
-
- static int l_resume(lua_State* L)
- {
- Audio::get()->resume();
- return 0;
- }
-
- static int l_setVolume(lua_State* L)
- {
- float volume = luax_checknumber(L, 1);
- Audio::get()->setVolume(volume);
- return 0;
- }
-
- static int l_newSource(lua_State* L)
- {
- AssetDatabase* fs = AssetDatabase::get();
- const char* f = luax_checkstring(L, 1);
- Buffer b;
- if (!fs->exists(f))
+
+ static int l_play(lua_State* L)
+ {
+ Audio::get()->play();
+ return 0;
+ }
+
+ static int l_stop(lua_State* L)
{
- error(L, "No such image %s", f);
- goto fail;
+ Audio::get()->stop();
+ return 0;
}
- if (!fs->read(f, &b))
+
+ static int l_pause(lua_State* L)
+ {
+ Audio::get()->pause();
+ return 0;
+ }
+
+ static int l_resume(lua_State* L)
+ {
+ Audio::get()->resume();
+ return 0;
+ }
+
+ static int l_setVolume(lua_State* L)
{
- error(L, "Failed to read source file %s", f);
- goto fail;
+ float volume = luax_checknumber(L, 1);
+ Audio::get()->setVolume(volume);
+ return 0;
}
- Source* src = Source::createSource(b.data, b.size);
- if (src == nullptr)
+
+ static int l_newSource(lua_State* L)
{
- error(L, "Failed to decode source file %s", f);
- goto fail;
+ AssetDatabase* fs = AssetDatabase::get();
+ const char* f = luax_checkstring(L, 1);
+ Buffer b;
+ if (!fs->exists(f))
+ {
+ error(L, "No such image %s", f);
+ goto fail;
+ }
+ if (!fs->read(f, &b))
+ {
+ error(L, "Failed to read source file %s", f);
+ goto fail;
+ }
+ Source* src = Source::createSource(b.data, b.size);
+ if (src == nullptr)
+ {
+ error(L, "Failed to decode source file %s", f);
+ goto fail;
+ }
+ Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_AUDIO_SOURCE, sizeof(Proxy));
+ proxy->bind(new Ref<Source>(src, JIN_AUDIO_SOURCE));
+ return 1;
+ fail:
+ luax_pushnil(L);
+ return 1;
}
- Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_AUDIO_SOURCE, sizeof(Proxy));
- proxy->bind(new Ref<Source>(src, JIN_AUDIO_SOURCE));
- return 1;
- fail:
- luax_pushnil(L);
- return 1;
- }
- static int l_destroy(lua_State* L)
- {
- Audio* audio = Audio::get();
- audio->quit();
- return 0;
- }
-
- static const luaL_Reg f[] = {
- { "init", l_init },
- { "play", l_play },
- { "stop", l_stop },
- { "pause", l_pause },
- { "resume", l_resume },
- { "setVolume", l_setVolume },
- { "newSource", l_newSource },
- { "destroy", l_destroy },
- { 0, 0 }
- };
-
- extern int luaopen_Source(lua_State* L);
-
- int luaopen_audio(lua_State* L)
- {
- luaopen_Source(L);
-
- luax_newlib(L, f);
-
- return 1;
- }
-
-} // lua
-} // jin \ No newline at end of file
+ static int l_destroy(lua_State* L)
+ {
+ Audio* audio = Audio::get();
+ audio->quit();
+ return 0;
+ }
+
+ static const luaL_Reg f[] = {
+ { "init", l_init },
+ { "play", l_play },
+ { "stop", l_stop },
+ { "pause", l_pause },
+ { "resume", l_resume },
+ { "setVolume", l_setVolume },
+ { "newSource", l_newSource },
+ { "destroy", l_destroy },
+ { 0, 0 }
+ };
+
+ extern int luaopen_Source(lua_State* L);
+
+ int luaopen_audio(lua_State* L)
+ {
+ luaopen_Source(L);
+
+ luax_newlib(L, f);
+
+ return 1;
+ }
+
+ } // Lua
+} // JinEngine \ No newline at end of file