Try to fix nasty corner cases of failing loads
[lsnes.git] / lua / gui-core.cpp
blob994ef019eaff26a2697794988430a354edd47f33
1 #include "lua-int.hpp"
3 namespace
5 class lua_gui_resolution : public lua_function
7 public:
8 lua_gui_resolution() : lua_function("gui.resolution") {}
9 int invoke(lua_State* LS)
11 if(!lua_render_ctx)
12 return 0;
13 lua_pushnumber(LS, lua_render_ctx->width);
14 lua_pushnumber(LS, lua_render_ctx->height);
15 lua_pushnumber(LS, lua_render_ctx->rshift);
16 lua_pushnumber(LS, lua_render_ctx->gshift);
17 lua_pushnumber(LS, lua_render_ctx->bshift);
18 return 5;
20 } gui_resolution;
22 template<uint32_t lua_render_context::*gap>
23 class lua_gui_set_gap : public lua_function
25 public:
26 lua_gui_set_gap(const std::string& name) : lua_function(name) {}
27 int invoke(lua_State* LS)
29 if(!lua_render_ctx)
30 return 0;
31 uint32_t g = get_numeric_argument<uint32_t>(LS, 1, fname.c_str());
32 if(g > 8192)
33 return 0; //Ignore ridiculous gap.
34 lua_render_ctx->*gap = g;
35 return 0;
39 lua_gui_set_gap<&lua_render_context::left_gap> lg("gui.left_gap");
40 lua_gui_set_gap<&lua_render_context::right_gap> rg("gui.right_gap");
41 lua_gui_set_gap<&lua_render_context::top_gap> tg("gui.top_gap");
42 lua_gui_set_gap<&lua_render_context::bottom_gap> bg("gui.bottom_gap");
44 function_ptr_luafun gui_repaint("gui.repaint", [](lua_State* LS, const std::string& fname) -> int {
45 lua_requests_repaint = true;
46 return 0;
47 });
49 function_ptr_luafun gui_sfupd("gui.subframe_update", [](lua_State* LS, const std::string& fname) -> int {
50 lua_requests_subframe_paint = get_boolean_argument(LS, 1, fname.c_str());
51 return 0;
52 });