From 98c9825c49a1674f59eafb3253829ca7d5cac3c1 Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 14 Jan 2019 16:40:14 +0800 Subject: *rename source file --- src/libjin-lua/modules/audio/je_lua_audio.cpp | 132 ------------------------- src/libjin-lua/modules/audio/je_lua_audio.h | 16 --- src/libjin-lua/modules/audio/je_lua_source.cpp | 114 --------------------- src/libjin-lua/modules/audio/je_lua_source.h | 16 --- src/libjin-lua/modules/audio/l_audio.cpp | 132 +++++++++++++++++++++++++ src/libjin-lua/modules/audio/l_audio.h | 16 +++ src/libjin-lua/modules/audio/l_source.cpp | 114 +++++++++++++++++++++ src/libjin-lua/modules/audio/l_source.h | 16 +++ 8 files changed, 278 insertions(+), 278 deletions(-) delete mode 100644 src/libjin-lua/modules/audio/je_lua_audio.cpp delete mode 100644 src/libjin-lua/modules/audio/je_lua_audio.h delete mode 100644 src/libjin-lua/modules/audio/je_lua_source.cpp delete mode 100644 src/libjin-lua/modules/audio/je_lua_source.h create mode 100644 src/libjin-lua/modules/audio/l_audio.cpp create mode 100644 src/libjin-lua/modules/audio/l_audio.h create mode 100644 src/libjin-lua/modules/audio/l_source.cpp create mode 100644 src/libjin-lua/modules/audio/l_source.h (limited to 'src/libjin-lua/modules/audio') diff --git a/src/libjin-lua/modules/audio/je_lua_audio.cpp b/src/libjin-lua/modules/audio/je_lua_audio.cpp deleted file mode 100644 index d5cfb43..0000000 --- a/src/libjin-lua/modules/audio/je_lua_audio.cpp +++ /dev/null @@ -1,132 +0,0 @@ -#include "common/je_lua.h" -#include "common/je_lua_common.h" -#include "libjin/jin.h" -#include "je_lua_source.h" - -using namespace JinEngine::Audio; -using namespace JinEngine::Audio::SDL; -using namespace JinEngine::Filesystem; - -namespace JinEngine -{ - namespace Lua - { - - typedef SDLAudio Audio; - typedef SDLSource Source; - - struct - { - bool initialized = false; - } context; - - LUA_IMPLEMENT int l_init(lua_State* L) - { - if (context.initialized) - { - // Already initialized. - luax_pushboolean(L, true); - return 1; - } - Audio::Setting setting; - setting.samplerate = 44100; - setting.samples = 44100; - Audio* audio = Audio::get(); - context.initialized = audio->start(&setting); - if (!context.initialized) - { - luax_error(L, "could not init audio"); - luax_pushboolean(L, false); - return 1; - } - luax_pushboolean(L, true); - return 1; - } - - LUA_IMPLEMENT int l_play(lua_State* L) - { - Audio::get()->play(); - return 0; - } - - LUA_IMPLEMENT int l_stop(lua_State* L) - { - Audio::get()->stop(); - return 0; - } - - LUA_IMPLEMENT int l_pause(lua_State* L) - { - Audio::get()->pause(); - return 0; - } - - LUA_IMPLEMENT int l_resume(lua_State* L) - { - Audio::get()->resume(); - return 0; - } - - LUA_IMPLEMENT int l_setVolume(lua_State* L) - { - float volume = luax_checknumber(L, 1); - Audio::get()->setVolume(volume); - return 0; - } - - LUA_IMPLEMENT int l_newSource(lua_State* L) - { - AssetDatabase* fs = AssetDatabase::get(); - const char* f = luax_checkstring(L, 1); - Buffer b; - try - { - if (!fs->exists(f)) - throw Exception("No such source file %s.", f); - fs->read(f, b); - } - catch (Exception& e) - { - luax_errorf(L, "Failed to read source file %s", f); - luax_pushnil(L); - return 1; - } - Source* src = new SDLSource((void*)&b, b.size()); - if (src == nullptr) - { - luax_errorf(L, "Failed to decode source file %s", f); - luax_pushnil(L); - return 1; - } - LuaObject* luaObj = luax_newinstance(L, Jin_Lua_Source, new Shared(src)); - return 1; - } - - LUA_IMPLEMENT int l_destroy(lua_State* L) - { - Audio* audio = Audio::get(); - audio->quit(); - return 0; - } - - LUA_EXPORT int luaopen_audio(lua_State* L) - { - luaopen_Source(L); - - luaL_Reg methods[] = { - { "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 } - }; - luax_newlib(L, methods); - return 1; - } - - } // namespace Lua -} // namespace JinEngine \ No newline at end of file diff --git a/src/libjin-lua/modules/audio/je_lua_audio.h b/src/libjin-lua/modules/audio/je_lua_audio.h deleted file mode 100644 index 6b4669a..0000000 --- a/src/libjin-lua/modules/audio/je_lua_audio.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef __JE_LUA_AUDIO_H__ -#define __JE_LUA_AUDIO_H__ - -#include "je_lua_audio.h" - -namespace JinEngine -{ - namespace Lua - { - - int luaopen_audio(lua_State* L); - - } -} - -#endif \ No newline at end of file diff --git a/src/libjin-lua/modules/audio/je_lua_source.cpp b/src/libjin-lua/modules/audio/je_lua_source.cpp deleted file mode 100644 index 8c9e247..0000000 --- a/src/libjin-lua/modules/audio/je_lua_source.cpp +++ /dev/null @@ -1,114 +0,0 @@ -#include "libjin/jin.h" -#include "common/je_lua.h" -#include "common/je_lua_common.h" - -using namespace JinEngine::Audio; - -namespace JinEngine -{ - namespace Lua - { - - const char* Jin_Lua_Source = "Source"; - - LUA_IMPLEMENT inline Source* checkSource(lua_State* L) - { - LuaObject* luaObj = luax_checkobject(L, 1, Jin_Lua_Source); - Source* source = luaObj->getObject(); - return source; - } - - LUA_IMPLEMENT int l_play(lua_State* L) - { - Source* source = checkSource(L); - source->play(); - return 0; - } - - LUA_IMPLEMENT int l_stop(lua_State* L) - { - Source* source = checkSource(L); - source->stop(); - return 0; - } - - LUA_IMPLEMENT int l_pause(lua_State* L) - { - Source* source = checkSource(L); - source->pause(); - return 0; - } - - LUA_IMPLEMENT int l_rewind(lua_State* L) - { - Source* source = checkSource(L); - source->rewind(); - return 0; - } - - LUA_IMPLEMENT int l_resume(lua_State* L) - { - Source* source = checkSource(L); - source->resume(); - return 0; - } - - LUA_IMPLEMENT int l_isStop(lua_State* L) - { - Source* source = checkSource(L); - bool isStop = source->isStopped(); - luax_pushboolean(L, isStop); - return 1; - } - - LUA_IMPLEMENT int l_isPaused(lua_State* L) - { - Source* source = checkSource(L); - bool isPaused = source->isPaused(); - luax_pushboolean(L, isPaused); - return 1; - } - - LUA_IMPLEMENT int l_setVolume(lua_State* L) - { - Source* source = checkSource(L); - float volume = luax_checknumber(L, 2); - source->setVolume(volume); - return 0; - } - - LUA_IMPLEMENT int l_setLoop(lua_State* L) - { - Source* source = checkSource(L); - bool loop = luax_checkbool(L, 2); - source->setLoop(loop); - return 0; - } - - LUA_IMPLEMENT int l_gc(lua_State* L) - { - LuaObject* luaObj = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Source); - luaObj->release(); - return 0; - } - - LUA_EXPORT void luaopen_Source(lua_State* L) - { - luaL_Reg methods[] = { - { "__gc", l_gc }, - { "play", l_play }, - { "stop", l_stop }, - { "pause", l_pause }, - { "resume", l_resume }, - { "rewind", l_rewind }, - { "isStop", l_isStop }, - { "isPaused", l_isPaused }, - { "setVolume", l_setVolume }, - { "setLoop", l_setLoop }, - { 0, 0 } - }; - luax_newtype(L, Jin_Lua_Source, methods); - } - - } // namespace Lua -} // namespace JinEngine \ No newline at end of file diff --git a/src/libjin-lua/modules/audio/je_lua_source.h b/src/libjin-lua/modules/audio/je_lua_source.h deleted file mode 100644 index f7e6b48..0000000 --- a/src/libjin-lua/modules/audio/je_lua_source.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef __JE_LUA_SOURCE_H__ -#define __JE_LUA_SOURCE_H__ - -namespace JinEngine -{ - namespace Lua - { - - extern const char* Jin_Lua_Source; - - void luaopen_Source(lua_State* L); - - } -} - -#endif \ No newline at end of file diff --git a/src/libjin-lua/modules/audio/l_audio.cpp b/src/libjin-lua/modules/audio/l_audio.cpp new file mode 100644 index 0000000..9ad4228 --- /dev/null +++ b/src/libjin-lua/modules/audio/l_audio.cpp @@ -0,0 +1,132 @@ +#include "common/je_lua.h" +#include "common/l_common.h" +#include "libjin/jin.h" +#include "l_source.h" + +using namespace JinEngine::Audio; +using namespace JinEngine::Audio::SDL; +using namespace JinEngine::Filesystem; + +namespace JinEngine +{ + namespace Lua + { + + typedef SDLAudio Audio; + typedef SDLSource Source; + + struct + { + bool initialized = false; + } context; + + LUA_IMPLEMENT int l_init(lua_State* L) + { + if (context.initialized) + { + // Already initialized. + luax_pushboolean(L, true); + return 1; + } + Audio::Setting setting; + setting.samplerate = 44100; + setting.samples = 44100; + Audio* audio = Audio::get(); + context.initialized = audio->start(&setting); + if (!context.initialized) + { + luax_error(L, "could not init audio"); + luax_pushboolean(L, false); + return 1; + } + luax_pushboolean(L, true); + return 1; + } + + LUA_IMPLEMENT int l_play(lua_State* L) + { + Audio::get()->play(); + return 0; + } + + LUA_IMPLEMENT int l_stop(lua_State* L) + { + Audio::get()->stop(); + return 0; + } + + LUA_IMPLEMENT int l_pause(lua_State* L) + { + Audio::get()->pause(); + return 0; + } + + LUA_IMPLEMENT int l_resume(lua_State* L) + { + Audio::get()->resume(); + return 0; + } + + LUA_IMPLEMENT int l_setVolume(lua_State* L) + { + float volume = luax_checknumber(L, 1); + Audio::get()->setVolume(volume); + return 0; + } + + LUA_IMPLEMENT int l_newSource(lua_State* L) + { + AssetDatabase* fs = AssetDatabase::get(); + const char* f = luax_checkstring(L, 1); + Buffer b; + try + { + if (!fs->exists(f)) + throw Exception("No such source file %s.", f); + fs->read(f, b); + } + catch (Exception& e) + { + luax_errorf(L, "Failed to read source file %s", f); + luax_pushnil(L); + return 1; + } + Source* src = new SDLSource((void*)&b, b.size()); + if (src == nullptr) + { + luax_errorf(L, "Failed to decode source file %s", f); + luax_pushnil(L); + return 1; + } + LuaObject* luaObj = luax_newinstance(L, Jin_Lua_Source, new Shared(src)); + return 1; + } + + LUA_IMPLEMENT int l_destroy(lua_State* L) + { + Audio* audio = Audio::get(); + audio->quit(); + return 0; + } + + LUA_EXPORT int luaopen_audio(lua_State* L) + { + luaopen_Source(L); + + luaL_Reg methods[] = { + { "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 } + }; + luax_newlib(L, methods); + return 1; + } + + } // namespace Lua +} // namespace JinEngine \ No newline at end of file diff --git a/src/libjin-lua/modules/audio/l_audio.h b/src/libjin-lua/modules/audio/l_audio.h new file mode 100644 index 0000000..c025fdf --- /dev/null +++ b/src/libjin-lua/modules/audio/l_audio.h @@ -0,0 +1,16 @@ +#ifndef __JE_LUA_AUDIO_H__ +#define __JE_LUA_AUDIO_H__ + +#include "l_audio.h" + +namespace JinEngine +{ + namespace Lua + { + + int luaopen_audio(lua_State* L); + + } +} + +#endif \ No newline at end of file diff --git a/src/libjin-lua/modules/audio/l_source.cpp b/src/libjin-lua/modules/audio/l_source.cpp new file mode 100644 index 0000000..72af871 --- /dev/null +++ b/src/libjin-lua/modules/audio/l_source.cpp @@ -0,0 +1,114 @@ +#include "libjin/jin.h" +#include "common/je_lua.h" +#include "common/l_common.h" + +using namespace JinEngine::Audio; + +namespace JinEngine +{ + namespace Lua + { + + const char* Jin_Lua_Source = "Source"; + + LUA_IMPLEMENT inline Source* checkSource(lua_State* L) + { + LuaObject* luaObj = luax_checkobject(L, 1, Jin_Lua_Source); + Source* source = luaObj->getObject(); + return source; + } + + LUA_IMPLEMENT int l_play(lua_State* L) + { + Source* source = checkSource(L); + source->play(); + return 0; + } + + LUA_IMPLEMENT int l_stop(lua_State* L) + { + Source* source = checkSource(L); + source->stop(); + return 0; + } + + LUA_IMPLEMENT int l_pause(lua_State* L) + { + Source* source = checkSource(L); + source->pause(); + return 0; + } + + LUA_IMPLEMENT int l_rewind(lua_State* L) + { + Source* source = checkSource(L); + source->rewind(); + return 0; + } + + LUA_IMPLEMENT int l_resume(lua_State* L) + { + Source* source = checkSource(L); + source->resume(); + return 0; + } + + LUA_IMPLEMENT int l_isStop(lua_State* L) + { + Source* source = checkSource(L); + bool isStop = source->isStopped(); + luax_pushboolean(L, isStop); + return 1; + } + + LUA_IMPLEMENT int l_isPaused(lua_State* L) + { + Source* source = checkSource(L); + bool isPaused = source->isPaused(); + luax_pushboolean(L, isPaused); + return 1; + } + + LUA_IMPLEMENT int l_setVolume(lua_State* L) + { + Source* source = checkSource(L); + float volume = luax_checknumber(L, 2); + source->setVolume(volume); + return 0; + } + + LUA_IMPLEMENT int l_setLoop(lua_State* L) + { + Source* source = checkSource(L); + bool loop = luax_checkbool(L, 2); + source->setLoop(loop); + return 0; + } + + LUA_IMPLEMENT int l_gc(lua_State* L) + { + LuaObject* luaObj = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Source); + luaObj->release(); + return 0; + } + + LUA_EXPORT void luaopen_Source(lua_State* L) + { + luaL_Reg methods[] = { + { "__gc", l_gc }, + { "play", l_play }, + { "stop", l_stop }, + { "pause", l_pause }, + { "resume", l_resume }, + { "rewind", l_rewind }, + { "isStop", l_isStop }, + { "isPaused", l_isPaused }, + { "setVolume", l_setVolume }, + { "setLoop", l_setLoop }, + { 0, 0 } + }; + luax_newtype(L, Jin_Lua_Source, methods); + } + + } // namespace Lua +} // namespace JinEngine \ No newline at end of file diff --git a/src/libjin-lua/modules/audio/l_source.h b/src/libjin-lua/modules/audio/l_source.h new file mode 100644 index 0000000..f7e6b48 --- /dev/null +++ b/src/libjin-lua/modules/audio/l_source.h @@ -0,0 +1,16 @@ +#ifndef __JE_LUA_SOURCE_H__ +#define __JE_LUA_SOURCE_H__ + +namespace JinEngine +{ + namespace Lua + { + + extern const char* Jin_Lua_Source; + + void luaopen_Source(lua_State* L); + + } +} + +#endif \ No newline at end of file -- cgit v1.1-26-g67d0