aboutsummaryrefslogtreecommitdiff
path: root/src/lua/modules/audio/je_lua_source.cpp
blob: 2297feaff2778ec371111c5389769db81b730151 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include "libjin/jin.h"
#include "lua/modules/luax.h"
#include "lua/common/je_lua_common.h"
#include "lua/modules/types.h"

using namespace JinEngine::Audio;

namespace JinEngine
{
    namespace Lua
    {

        typedef Shared<Source>& SharedSource;

        LUA_IMPLEMENT inline SharedSource checkSource(lua_State* L)
        {
            Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_AUDIO_SOURCE);
		    return proxy->getShared<Source>();
        }

        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_AUDIO_SOURCE);
            proxy->release();
            return 0;
        }

        LUA_IMPLEMENT 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           }
        };
    
        LUA_EXPORT int luaopen_Source(lua_State* L)
        {
            luax_newtype(L, JIN_AUDIO_SOURCE, f);
            return 0; 
        }

    } // namespace Lua
} // namespace JinEngine