1 #include "core/keymapper.hpp"
2 #include "core/lua-int.hpp"
3 #include "core/movie.hpp"
4 #include "core/moviedata.hpp"
8 function_ptr_luafun
iset("input.set", [](lua_State
* LS
, const std::string
& fname
) -> int {
9 if(!lua_input_controllerdata
)
11 unsigned controller
= get_numeric_argument
<unsigned>(LS
, 1, fname
.c_str());
12 unsigned index
= get_numeric_argument
<unsigned>(LS
, 2, fname
.c_str());
13 short value
= get_numeric_argument
<short>(LS
, 3, fname
.c_str());
14 if(controller
>= MAX_PORTS
* MAX_CONTROLLERS_PER_PORT
|| index
> MAX_CONTROLS_PER_CONTROLLER
)
16 lua_input_controllerdata
->axis(controller
, index
, value
);
20 function_ptr_luafun
iget("input.get", [](lua_State
* LS
, const std::string
& fname
) -> int {
21 if(!lua_input_controllerdata
)
23 unsigned controller
= get_numeric_argument
<unsigned>(LS
, 1, fname
.c_str());
24 unsigned index
= get_numeric_argument
<unsigned>(LS
, 2, fname
.c_str());
25 if(controller
>= MAX_PORTS
* MAX_CONTROLLERS_PER_PORT
|| index
> MAX_CONTROLS_PER_CONTROLLER
)
27 lua_pushnumber(LS
, lua_input_controllerdata
->axis(controller
, index
));
31 function_ptr_luafun
iseta("input.seta", [](lua_State
* LS
, const std::string
& fname
) -> int {
32 if(!lua_input_controllerdata
)
35 unsigned controller
= get_numeric_argument
<unsigned>(LS
, 1, fname
.c_str());
36 if(controller
>= MAX_PORTS
* MAX_CONTROLLERS_PER_PORT
)
38 uint64_t base
= get_numeric_argument
<uint64_t>(LS
, 2, fname
.c_str());
39 for(unsigned i
= 0; i
< MAX_CONTROLS_PER_CONTROLLER
; i
++) {
40 val
= (base
>> i
) & 1;
41 get_numeric_argument
<short>(LS
, i
+ 3, val
, fname
.c_str());
42 lua_input_controllerdata
->axis(controller
, i
, val
);
47 function_ptr_luafun
igeta("input.geta", [](lua_State
* LS
, const std::string
& fname
) -> int {
48 if(!lua_input_controllerdata
)
50 unsigned controller
= get_numeric_argument
<unsigned>(LS
, 1, fname
.c_str());
51 if(controller
>= MAX_PORTS
* MAX_CONTROLLERS_PER_PORT
)
54 for(unsigned i
= 0; i
< MAX_CONTROLS_PER_CONTROLLER
; i
++)
55 if(lua_input_controllerdata
->axis(controller
, i
))
57 lua_pushnumber(LS
, fret
);
58 for(unsigned i
= 0; i
< MAX_CONTROLS_PER_CONTROLLER
; i
++)
59 lua_pushnumber(LS
, lua_input_controllerdata
->axis(controller
, i
));
60 return MAX_CONTROLS_PER_CONTROLLER
+ 1;
63 function_ptr_luafun
igett("input.controllertype", [](lua_State
* LS
, const std::string
& fname
) -> int {
64 unsigned controller
= get_numeric_argument
<unsigned>(LS
, 1, fname
.c_str());
65 auto& m
= get_movie();
66 controller_frame f
= m
.read_subframe(m
.get_current_frame(), 0);
67 porttype_t p
= f
.get_port_type(controller
/ MAX_CONTROLLERS_PER_PORT
);
68 const porttype_info
& i
= porttype_info::lookup(p
);
69 if(i
.controllers
<= controller
% MAX_CONTROLLERS_PER_PORT
)
73 else if(p
== PT_GAMEPAD
)
74 lua_pushstring(LS
, "gamepad");
75 else if(p
== PT_MULTITAP
)
76 lua_pushstring(LS
, "gamepad");
77 else if(p
== PT_MOUSE
)
78 lua_pushstring(LS
, "mouse");
79 else if(p
== PT_SUPERSCOPE
)
80 lua_pushstring(LS
, "superscope");
81 else if(p
== PT_JUSTIFIER
)
82 lua_pushstring(LS
, "justifier");
83 else if(p
== PT_JUSTIFIERS
)
84 lua_pushstring(LS
, "justifier");
86 lua_pushstring(LS
, "unknown");
90 function_ptr_luafun
ireset("input.reset", [](lua_State
* LS
, const std::string
& fname
) -> int {
91 if(!lua_input_controllerdata
)
94 get_numeric_argument(LS
, 1, cycles
, fname
.c_str());
97 short lo
= cycles
% 10000;
98 short hi
= cycles
/ 10000;
99 lua_input_controllerdata
->reset(true);
100 lua_input_controllerdata
->delay(std::make_pair(hi
, lo
));
104 function_ptr_luafun
iraw("input.raw", [](lua_State
* LS
, const std::string
& fname
) -> int {
105 auto s
= keygroup::get_all_parameters();
108 lua_pushstring(LS
, i
.first
.c_str());
109 push_keygroup_parameters(LS
, i
.second
);
110 lua_settable(LS
, -3);
115 function_ptr_luafun
ireq("input.keyhook", [](lua_State
* LS
, const std::string
& fname
) -> int {
118 std::string x
= get_string_argument(LS
, 1, fname
.c_str());
119 state
= get_boolean_argument(LS
, 2, fname
.c_str());
120 k
= keygroup::lookup_by_name(x
);
122 lua_pushstring(LS
, "Invalid key name");
126 k
->request_hook_callback(state
);