1 #include "lua/internal.hpp"
2 #include "interface/romtype.hpp"
3 #include "core/instance.hpp"
4 #include "core/moviedata.hpp"
5 #include "core/messages.hpp"
6 #include "core/rom.hpp"
10 int action(lua::state
& L
, lua::parameters
& P
)
17 const interface_action
* act
= NULL
;
18 for(auto i
: core
.rom
->get_actions())
19 if(i
->get_symbol() == name
) {
24 throw std::runtime_error("No such action");
25 if(!(core
.rom
->action_flags(act
->id
) & 1))
26 throw std::runtime_error("Action not enabled.");
27 std::vector
<interface_action_paramval
> params
;
28 for(auto i
: act
->params
) {
30 interface_action_paramval pv
;
31 if((r
= regex("string(:(.*))?", i
.model
))) {
35 if(r
[2] != "" && !regex_match(r
[2], pv
.s
))
38 messages
<< "Internal error: Bad constraint in '" << i
.model
<< "'."
40 throw std::runtime_error("Internal error");
43 throw std::runtime_error("String does not satisfy constraints.");
44 } else if((r
= regex("int:([0-9]+),([0-9]+)", i
.model
))) {
47 low
= parse_value
<int64_t>(r
[1]);
48 high
= parse_value
<int64_t>(r
[2]);
50 messages
<< "Internal error: Unknown limits in '" << i
.model
<< "'."
52 throw std::runtime_error("Internal error");
55 if(pv
.i
< low
|| pv
.i
> high
) {
56 throw std::runtime_error("Parameter out of limits.");
58 } else if((r
= regex("enum:(.*)", i
.model
))) {
66 if(i2
.type() == JSON::string
)
68 else if(i2
.type() == JSON::array
)
69 n
= i2
.index(0).as_string8();
71 throw std::runtime_error("Choice not array nor "
77 } catch(std::exception
& e
) {
78 messages
<< "JSON parse error parsing " << "model: "
79 << e
.what() << std::endl
;
80 throw std::runtime_error("Internal error");
82 throw std::runtime_error("Invalid choice for enumeration.");
85 } else if(regex_match("bool", i
.model
)) {
87 } else if(regex_match("toggle", i
.model
)) {
89 messages
<< "Internal error: Unknown parameter model '" << i
.model
<< "'."
91 throw std::runtime_error("Internal error");
96 throw std::runtime_error("Excess arguments for action");
97 core
.rom
->execute_action(act
->id
, params
);
101 int action_flags(lua::state
& L
, lua::parameters
& P
)
108 const interface_action
* act
= NULL
;
109 for(auto i
: core
.rom
->get_actions())
110 if(i
->get_symbol() == name
) {
115 throw std::runtime_error("No such action");
116 L
.pushnumber(core
.rom
->action_flags(act
->id
));
120 lua::functions
LUA_actions_fns(lua_func_misc
, "memory", {
122 {"action_flags", action_flags
},