aboutsummaryrefslogtreecommitdiff
path: root/src/lua/modules/audio/luaopen_Source.cpp
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2018-08-20 11:51:32 +0800
committerchai <chaifix@163.com>2018-08-20 11:51:32 +0800
commit65bafdc682db46f0f115374ad39f1fbc348832ac (patch)
tree7862548cdf01060e89a45c9817afc6e5d263acd7 /src/lua/modules/audio/luaopen_Source.cpp
parent9593ae6ecdfcfb876fa7953f25e19f0a97e1453a (diff)
*update
Diffstat (limited to 'src/lua/modules/audio/luaopen_Source.cpp')
-rw-r--r--src/lua/modules/audio/luaopen_Source.cpp115
1 files changed, 115 insertions, 0 deletions
diff --git a/src/lua/modules/audio/luaopen_Source.cpp b/src/lua/modules/audio/luaopen_Source.cpp
new file mode 100644
index 0000000..4c98ead
--- /dev/null
+++ b/src/lua/modules/audio/luaopen_Source.cpp
@@ -0,0 +1,115 @@
+#include "libjin/jin.h"
+#include "lua/modules/luax.h"
+#include "lua/common/common.h"
+
+namespace jin
+{
+namespace lua
+{
+
+ using namespace jin::audio;
+
+ typedef Ref<Source>& SourceRef;
+
+ static inline SourceRef checkSource(lua_State* L)
+ {
+ Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_AUDIO_SOURCE);
+ return proxy->getRef<Source>();
+ }
+
+ 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;
+ }
+
+} // lua
+} // jin \ No newline at end of file