From 831e814ce9bdb84e86c06c4a52008f6bdaaa00d6 Mon Sep 17 00:00:00 2001 From: chai Date: Fri, 16 Nov 2018 00:24:51 +0800 Subject: =?UTF-8?q?*=E5=90=88=E5=B9=B6master=E5=88=B0minimal=E5=88=86?= =?UTF-8?q?=E6=94=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lua/modules/audio/je_lua_source.cpp | 117 ++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 src/lua/modules/audio/je_lua_source.cpp (limited to 'src/lua/modules/audio/je_lua_source.cpp') diff --git a/src/lua/modules/audio/je_lua_source.cpp b/src/lua/modules/audio/je_lua_source.cpp new file mode 100644 index 0000000..e152847 --- /dev/null +++ b/src/lua/modules/audio/je_lua_source.cpp @@ -0,0 +1,117 @@ +#include "libjin/jin.h" +#include "lua/modules/luax.h" +#include "lua/common/je_lua_common.h" + + +using namespace JinEngine::Audio; + +namespace JinEngine +{ + namespace Lua + { + + const char* Jin_Lua_Source = "Source"; + + typedef Shared& SharedSource; + + LUA_IMPLEMENT inline SharedSource checkSource(lua_State* L) + { + Proxy* proxy = (Proxy*)luax_checktype(L, 1, Jin_Lua_Source); + return proxy->getShared(); + } + + LUA_IMPLEMENT int l_play(lua_State* L) + { + SharedSource shared = checkSource(L); + shared->play(); + return 0; + } + + LUA_IMPLEMENT int l_stop(lua_State* L) + { + SharedSource shared = checkSource(L); + shared->stop(); + return 0; + } + + LUA_IMPLEMENT int l_pause(lua_State* L) + { + SharedSource shared = checkSource(L); + shared->pause(); + return 0; + } + + LUA_IMPLEMENT int l_rewind(lua_State* L) + { + SharedSource shared = checkSource(L); + shared->rewind(); + return 0; + } + + LUA_IMPLEMENT int l_resume(lua_State* L) + { + SharedSource shared = checkSource(L); + shared->resume(); + return 0; + } + + LUA_IMPLEMENT int l_isStop(lua_State* L) + { + SharedSource shared = checkSource(L); + bool isStop = shared->isStopped(); + luax_pushboolean(L, isStop); + return 1; + } + + LUA_IMPLEMENT int l_isPaused(lua_State* L) + { + SharedSource shared = checkSource(L); + bool isPaused = shared->isPaused(); + luax_pushboolean(L, isPaused); + return 1; + } + + LUA_IMPLEMENT int l_setVolume(lua_State* L) + { + SharedSource shared = checkSource(L); + float volume = luax_checknumber(L, 2); + shared->setVolume(volume); + return 0; + } + + LUA_IMPLEMENT int l_setLoop(lua_State* L) + { + SharedSource shared = checkSource(L); + bool loop = luax_checkbool(L, 2); + shared->setLoop(loop); + return 0; + } + + LUA_IMPLEMENT int l_gc(lua_State* L) + { + Proxy* proxy = (Proxy*)luax_checktype(L, 1, Jin_Lua_Source); + proxy->release(); + return 0; + } + + LUA_EXPORT void luaopen_Source(lua_State* L) + { + luaL_Reg f[] = { + { "__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, f); + } + + } // namespace Lua +} // namespace JinEngine \ No newline at end of file -- cgit v1.1-26-g67d0