Lua: input.keyhook
[lsnes.git] / include / core / lua.hpp
blob318ee1553e0056a938fcd2d0e1fab4787c0d271e
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) 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_readwrite() throw();
77 void lua_callback_startup() throw();
78 void lua_callback_pre_load(const std::string& name) throw();
79 void lua_callback_err_load(const std::string& name) throw();
80 void lua_callback_post_load(const std::string& name, bool was_state) throw();
81 void lua_callback_pre_save(const std::string& name, bool is_state) throw();
82 void lua_callback_err_save(const std::string& name) throw();
83 void lua_callback_post_save(const std::string& name, bool is_state) throw();
84 void lua_callback_snoop_input(uint32_t port, uint32_t controller, uint32_t index, short value) throw();
85 void lua_callback_quit() throw();
86 void lua_callback_keyhook(const std::string& key, const struct keygroup::parameters& p) throw();
88 extern bool lua_supported;
89 extern bool lua_requests_repaint;
90 extern bool lua_requests_subframe_paint;
92 #endif