Merge remote-tracking branch 'origin/rr1-maint'
[lsnes.git] / include / lua / lua.hpp
blob086ee4ffbe07b6bc7e1753959738fe7c9142aeed
1 #ifndef _lua__hpp__included__
2 #define _lua__hpp__included__
4 #include "core/controllerframe.hpp"
5 #include "core/keymapper.hpp"
6 #include "core/render.hpp"
8 struct lua_State;
10 /**
11 * Function implemented in C++ exported to Lua.
13 class lua_function
15 public:
16 /**
17 * Register function.
19 lua_function(const std::string& name) throw(std::bad_alloc);
20 /**
21 * Unregister function.
23 virtual ~lua_function() throw();
25 /**
26 * Invoke function.
28 virtual int invoke(lua_State* L) = 0;
29 protected:
30 std::string fname;
33 /**
34 * Register function pointer as lua function.
36 class function_ptr_luafun : public lua_function
38 public:
39 /**
40 * Register.
42 function_ptr_luafun(const std::string& name, int (*_fn)(lua_State* L, const std::string& fname))
43 : lua_function(name)
45 fn = _fn;
47 /**
48 * Invoke function.
50 int invoke(lua_State* L)
52 return fn(L, fname);
54 private:
55 int (*fn)(lua_State* L, const std::string& fname);
58 struct lua_render_context
60 uint32_t left_gap;
61 uint32_t right_gap;
62 uint32_t top_gap;
63 uint32_t bottom_gap;
64 struct render_queue* queue;
65 uint32_t width;
66 uint32_t height;
69 void init_lua() throw();
70 void quit_lua() throw();
71 void lua_callback_do_paint(struct lua_render_context* ctx, bool non_synthethic) throw();
72 void lua_callback_do_video(struct lua_render_context* ctx) throw();
73 void lua_callback_do_input(controller_frame& data, bool subframe) throw();
74 void lua_callback_do_reset() throw();
75 void lua_callback_do_frame() throw();
76 void lua_callback_do_frame_emulated() throw();
77 void lua_callback_do_rewind() throw();
78 void lua_callback_do_readwrite() throw();
79 void lua_callback_startup() throw();
80 void lua_callback_do_idle() throw();
81 void lua_callback_do_timer() throw();
82 void lua_callback_pre_load(const std::string& name) throw();
83 void lua_callback_err_load(const std::string& name) throw();
84 void lua_callback_post_load(const std::string& name, bool was_state) throw();
85 void lua_callback_pre_save(const std::string& name, bool is_state) throw();
86 void lua_callback_err_save(const std::string& name) throw();
87 void lua_callback_post_save(const std::string& name, bool is_state) throw();
88 void lua_callback_snoop_input(uint32_t port, uint32_t controller, uint32_t index, short value) throw();
89 void lua_callback_quit() throw();
90 void lua_callback_keyhook(const std::string& key, const struct keygroup::parameters& p) throw();
92 #define LUA_TIMED_HOOK_IDLE 0
93 #define LUA_TIMED_HOOK_TIMER 1
95 uint64_t lua_timed_hook(int timer) throw();
97 extern bool lua_supported;
98 extern bool lua_requests_repaint;
99 extern bool lua_requests_subframe_paint;
101 #endif