1 #ifndef _lua__hpp__included__
2 #define _lua__hpp__included__
7 #include "core/controllerframe.hpp"
8 #include "library/command.hpp"
9 #include "library/movie.hpp"
10 #include "library/framebuffer.hpp"
11 #include "library/lua-base.hpp"
12 #include "library/lua-framebuffer.hpp"
13 #include "library/memtracker.hpp"
14 #include "library/settingvar.hpp"
16 namespace command
{ class group
; }
17 namespace keyboard
{ class key
; }
19 #define LUA_TIMED_HOOK_IDLE 0
20 #define LUA_TIMED_HOOK_TIMER 1
22 class emulator_instance
;
24 void init_lua(emulator_instance
& inst
) throw();
25 void quit_lua(emulator_instance
& inst
) throw();
29 lua_state(lua::state
& _L
, command::group
& _command
, settingvar::group
& settings
);
32 void callback_do_paint(struct lua::render_context
* ctx
, bool non_synthethic
) throw();
33 void callback_do_video(struct lua::render_context
* ctx
, bool& kill_frame
, uint32_t& hscl
, uint32_t& vscl
)
35 void callback_do_input(portctrl::frame
& data
, bool subframe
) throw();
36 void callback_do_reset() throw();
37 void callback_do_frame() throw();
38 void callback_do_frame_emulated() throw();
39 void callback_do_rewind() throw();
40 void callback_do_readwrite() throw();
41 void callback_do_idle() throw();
42 void callback_do_timer() throw();
43 void callback_pre_load(const std::string
& name
) throw();
44 void callback_err_load(const std::string
& name
) throw();
45 void callback_post_load(const std::string
& name
, bool was_state
) throw();
46 void callback_pre_save(const std::string
& name
, bool is_state
) throw();
47 void callback_err_save(const std::string
& name
) throw();
48 void callback_post_save(const std::string
& name
, bool is_state
) throw();
49 void callback_snoop_input(uint32_t port
, uint32_t controller
, uint32_t index
, short value
) throw();
50 void callback_quit() throw();
51 void callback_keyhook(const std::string
& key
, keyboard::key
& p
) throw();
52 void callback_do_unsafe_rewind(movie
& mov
, void* u
);
53 bool callback_do_button(uint32_t port
, uint32_t controller
, uint32_t index
, const char* type
);
54 void callback_movie_lost(const char* what
);
55 void callback_do_latch(std::list
<std::string
>& args
);
56 void callback_frob_with_value(unsigned a
, unsigned b
, unsigned c
, short& d
);
57 void run_startup_scripts();
58 void add_startup_script(const std::string
& file
);
60 uint64_t timed_hook(int timer
) throw();
61 const std::map
<std::string
, std::u32string
>& get_watch_vars();
63 void do_eval_lua(const std::string
& c
);
64 void do_run_lua(const std::string
& c
);
65 void run_sysrc_lua(bool rerun
);
66 void set_r16m_dump(FILE* fp
);
68 bool requests_repaint
;
69 bool requests_subframe_paint
;
70 lua::render_context
* render_ctx
;
71 portctrl::frame
* input_controllerdata
;
73 void* synchronous_paint_ctx
;
78 std::set
<std::string
> hooked_keys
;
79 uint64_t idle_hook_time
;
80 uint64_t timer_hook_time
;
81 lua::render_context
* renderq_saved
;
82 lua::render_context
* renderq_last
;
83 bool renderq_redirect
;
84 void set_memory_limit(size_t max_mb
);
86 std::list
<std::string
> startup_scripts
;
87 std::map
<std::string
, std::u32string
> watch_vars
;
89 lua::state::callback_list
* on_paint
;
90 lua::state::callback_list
* on_video
;
91 lua::state::callback_list
* on_reset
;
92 lua::state::callback_list
* on_frame
;
93 lua::state::callback_list
* on_rewind
;
94 lua::state::callback_list
* on_idle
;
95 lua::state::callback_list
* on_timer
;
96 lua::state::callback_list
* on_frame_emulated
;
97 lua::state::callback_list
* on_readwrite
;
98 lua::state::callback_list
* on_startup
;
99 lua::state::callback_list
* on_pre_load
;
100 lua::state::callback_list
* on_post_load
;
101 lua::state::callback_list
* on_err_load
;
102 lua::state::callback_list
* on_pre_save
;
103 lua::state::callback_list
* on_post_save
;
104 lua::state::callback_list
* on_err_save
;
105 lua::state::callback_list
* on_input
;
106 lua::state::callback_list
* on_snoop
;
107 lua::state::callback_list
* on_snoop2
;
108 lua::state::callback_list
* on_button
;
109 lua::state::callback_list
* on_quit
;
110 lua::state::callback_list
* on_keyhook
;
111 lua::state::callback_list
* on_movie_lost
;
112 lua::state::callback_list
* on_pre_rewind
;
113 lua::state::callback_list
* on_post_rewind
;
114 lua::state::callback_list
* on_set_rewind
;
115 lua::state::callback_list
* on_latch
;
116 lua::state::callback_list
* on_frob_with_value
;
117 unsigned char r16m_fbuf
[16];
118 uint64_t r16m_empty_frame_count
;
122 void do_evaluate(const std::string
& a
);
123 bool run_lua_fragment();
124 template<typename
... T
> bool run_callback(lua::state::callback_list
& list
, T
... args
);
125 void run_synchronous_paint(struct lua::render_context
* ctx
);
127 command::group
& command
;
129 const char* luareader_fragment
;
130 command::_fnptr
<> resetcmd
;
131 command::_fnptr
<const std::string
&> evalcmd
;
132 command::_fnptr
<const std::string
&> evalcmd2
;
133 command::_fnptr
<command::arg_filename
> runcmd
;
134 struct _listener
: public settingvar::listener
136 _listener(settingvar::group
& group
, lua_state
& _obj
)
137 : obj(_obj
), grp(group
)
139 group
.add_listener(*this);
143 grp
.remove_listener(*this);
145 void on_setting_change(settingvar::group
& grp
, const settingvar::base
& val
);
147 settingvar::group
& grp
;