From ee8ef0433e36bf354a717bd4af679a0a5af2e6be Mon Sep 17 00:00:00 2001 From: chai Date: Thu, 20 Dec 2018 18:34:50 +0800 Subject: =?UTF-8?q?*=E4=BF=AE=E6=94=B9=E6=96=87=E4=BB=B6=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/libjin-lua/modules/audio/je_lua_source.cpp | 114 +++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 src/libjin-lua/modules/audio/je_lua_source.cpp (limited to 'src/libjin-lua/modules/audio/je_lua_source.cpp') diff --git a/src/libjin-lua/modules/audio/je_lua_source.cpp b/src/libjin-lua/modules/audio/je_lua_source.cpp new file mode 100644 index 0000000..8c9e247 --- /dev/null +++ b/src/libjin-lua/modules/audio/je_lua_source.cpp @@ -0,0 +1,114 @@ +#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 -- cgit v1.1-26-g67d0