aboutsummaryrefslogtreecommitdiff
path: root/src/lua/audio/luaopen_Source.cpp
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2018-07-29 13:02:15 +0800
committerchai <chaifix@163.com>2018-07-29 13:02:15 +0800
commitf94264fa4ba347fc362b4ae2deea5a12ff95f5af (patch)
treebe8f1dc893c3e464b894e00004cf77d5470b7623 /src/lua/audio/luaopen_Source.cpp
parent5560448bb78ed865aeb77f62cf85a2aed302779d (diff)
*update
Diffstat (limited to 'src/lua/audio/luaopen_Source.cpp')
-rw-r--r--src/lua/audio/luaopen_Source.cpp92
1 files changed, 87 insertions, 5 deletions
diff --git a/src/lua/audio/luaopen_Source.cpp b/src/lua/audio/luaopen_Source.cpp
index 8ecaf7e..0b8391a 100644
--- a/src/lua/audio/luaopen_Source.cpp
+++ b/src/lua/audio/luaopen_Source.cpp
@@ -1,26 +1,108 @@
#include "lua/luax.h"
+#include "libjin/jin.h"
+#include "../luaopen_types.h"
namespace jin
{
namespace lua
{
+ using namespace jin::audio;
+
+ static inline SDLSource* checkSource(lua_State* L)
+ {
+ Proxy* proxy = (Proxy*)luax_checktype(L, 1, TYPE_SOURCE);
+ if (proxy != 0 && proxy != nullptr)
+ return (SDLSource*)proxy->object;
+ return nullptr;
+ }
+
static int l_play(lua_State* L)
{
+ SDLSource* src = checkSource(L);
+ src->play();
+ return 0;
+ }
- return 0;
+ static int l_stop(lua_State* L)
+ {
+ SDLSource* src = checkSource(L);
+ src->stop();
+ return 0;
+ }
+
+ static int l_pause(lua_State* L)
+ {
+ SDLSource* src = checkSource(L);
+ src->pause();
+ return 0;
+ }
+
+ static int l_rewind(lua_State* L)
+ {
+ SDLSource* src = checkSource(L);
+ src->rewind();
+ return 0;
+ }
+
+ static int l_resume(lua_State* L)
+ {
+ SDLSource* src = checkSource(L);
+ src->resume();
+ return 0;
+ }
+
+ static int l_isStop(lua_State* L)
+ {
+ SDLSource* src = checkSource(L);
+ bool isStop = src->isStopped();
+ luax_pushboolean(L, isStop);
+ return 1;
+ }
+
+ static int l_isPaused(lua_State* L)
+ {
+ SDLSource* src = checkSource(L);
+ bool isPaused = src->isPaused();
+ luax_pushboolean(L, isPaused);
+ return 1;
+ }
+
+ static int l_setVolume(lua_State* L)
+ {
+ SDLSource* src = checkSource(L);
+ float volume = luax_checknumber(L, 2);
+ src->setVolume(volume);
+ return 0;
+ }
+
+ static int l_setLoop(lua_State* L)
+ {
+ SDLSource* src = checkSource(L);
+ bool loop = luax_checkbool(L, 2);
+ src->setLoop(loop);
+ return 0;
}
static const luaL_Reg f[] = {
- {"play", l_play},
+ { "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, TYPE_SOURCE, f);
- return 1;
+ return 0;
}
}
-}
+} \ No newline at end of file