From 6551adeca70d4299a99d45245d4e13dbfdfa87e5 Mon Sep 17 00:00:00 2001 From: chai Date: Tue, 23 Oct 2018 15:56:01 +0800 Subject: =?UTF-8?q?*=E4=BF=AE=E6=94=B9lua=E7=BB=91=E5=AE=9A=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E7=9A=84=E6=96=87=E4=BB=B6=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lua/modules/audio/je_lua_source.cpp | 116 ++++++++++++++++++++++++++++++++ 1 file changed, 116 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..bf43ceb --- /dev/null +++ b/src/lua/modules/audio/je_lua_source.cpp @@ -0,0 +1,116 @@ +#include "libjin/jin.h" +#include "lua/modules/luax.h" +#include "lua/common/common.h" +#include "lua/modules/types.h" + +namespace JinEngine +{ + namespace Lua + { + + using namespace JinEngine::Audio; + + typedef Ref& SourceRef; + + static inline SourceRef checkSource(lua_State* L) + { + Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_AUDIO_SOURCE); + return proxy->getRef(); + } + + static int l_play(lua_State* L) + { + SourceRef ref = checkSource(L); + ref->play(); + return 0; + } + + static int l_stop(lua_State* L) + { + SourceRef ref = checkSource(L); + ref->stop(); + return 0; + } + + static int l_pause(lua_State* L) + { + SourceRef ref = checkSource(L); + ref->pause(); + return 0; + } + + static int l_rewind(lua_State* L) + { + SourceRef ref = checkSource(L); + ref->rewind(); + return 0; + } + + static int l_resume(lua_State* L) + { + SourceRef ref = checkSource(L); + ref->resume(); + return 0; + } + + static int l_isStop(lua_State* L) + { + SourceRef ref = checkSource(L); + bool isStop = ref->isStopped(); + luax_pushboolean(L, isStop); + return 1; + } + + static int l_isPaused(lua_State* L) + { + SourceRef ref = checkSource(L); + bool isPaused = ref->isPaused(); + luax_pushboolean(L, isPaused); + return 1; + } + + static int l_setVolume(lua_State* L) + { + SourceRef ref = checkSource(L); + float volume = luax_checknumber(L, 2); + ref->setVolume(volume); + return 0; + } + + static int l_setLoop(lua_State* L) + { + SourceRef ref = checkSource(L); + bool loop = luax_checkbool(L, 2); + ref->setLoop(loop); + return 0; + } + + static int l_gc(lua_State* L) + { + Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_AUDIO_SOURCE); + proxy->release(); + return 0; + } + + static const 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 } + }; + + int luaopen_Source(lua_State* L) + { + luax_newtype(L, JIN_AUDIO_SOURCE, f); + return 0; + } + + } // namespace Lua +} // namespace JinEngine \ No newline at end of file -- cgit v1.1-26-g67d0