aboutsummaryrefslogtreecommitdiff
path: root/src/lua/modules/mouse/mouse.cpp
blob: 390936cd9fc769c2be0d062a5a23988926e64769 (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
#include "lua/modules/luax.h"
#include "libjin/jin.h"

namespace jin
{
namespace lua
{

    using namespace jin::input;

    static int l_pos(lua_State* L)
    {
        static Mouse* mouse = Mouse::get();
        int x, y; 
        mouse->getState(&x, &y);
        luax_pushnumber(L, x); 
        luax_pushnumber(L, y);
        return 2; 
    }

    static int l_setVisible(lua_State* L)
    {
        bool visible = luax_checkbool(L, 1);
        Mouse* mouse = Mouse::get(); 
        mouse->setVisible(visible);
        return 0;
    }

    static const luaL_Reg f[] = {
        { "position",   l_pos        },
        { "setVisible", l_setVisible },
        { 0,            0            }
    };
    
    int luaopen_mouse(lua_State* L)
    {
        luax_newlib(L, f);
        return 1;
    }

} // lua
} // jin