namespace {
+// Contains basically the same data as InputState, but does not hold on to
+// a reference to the frames. This is important so that we can release them
+// without having to wait for Lua's GC.
+struct InputStateInfo {
+ InputStateInfo(const InputState& input_state);
+
+ unsigned last_width[MAX_CARDS], last_height[MAX_CARDS];
+};
+
+InputStateInfo::InputStateInfo(const InputState &input_state)
+{
+ for (unsigned signal_num = 0; signal_num < MAX_CARDS; ++signal_num) {
+ BufferedFrame frame = input_state.buffered_frames[signal_num][0];
+ if (frame.frame == nullptr) {
+ last_width[signal_num] = last_height[signal_num] = 0;
+ continue;
+ }
+ const PBOFrameAllocator::Userdata *userdata = (const PBOFrameAllocator::Userdata *)frame.frame->userdata;
+ last_width[signal_num] = userdata->last_width[frame.field_number];
+ last_height[signal_num] = userdata->last_height[frame.field_number];
+ }
+}
+
class LuaRefWithDeleter {
public:
LuaRefWithDeleter(mutex *m, lua_State *L, int ref) : m(m), L(L), ref(ref) {}
return nullptr;
}
+InputStateInfo *get_input_state_info(lua_State *L, int idx)
+{
+ if (luaL_testudata(L, idx, "InputStateInfo")) {
+ return (InputStateInfo *)lua_touserdata(L, idx);
+ }
+ luaL_error(L, "Error: Index #%d was not InputStateInfo\n", idx);
+ return nullptr;
+}
+
bool checkbool(lua_State* L, int idx)
{
luaL_checktype(L, idx, LUA_TBOOLEAN);
return wrap_lua_object<MixEffect>(L, "MixEffect");
}
+int InputStateInfo_get_width(lua_State* L)
+{
+ assert(lua_gettop(L) == 2);
+ InputStateInfo *input_state_info = get_input_state_info(L, 1);
+ Theme *theme = get_theme_updata(L);
+ int signal_num = theme->map_signal(luaL_checknumber(L, 2));
+ lua_pushnumber(L, input_state_info->last_width[signal_num]);
+ return 1;
+}
+
+int InputStateInfo_get_height(lua_State* L)
+{
+ assert(lua_gettop(L) == 2);
+ InputStateInfo *input_state_info = get_input_state_info(L, 1);
+ Theme *theme = get_theme_updata(L);
+ int signal_num = theme->map_signal(luaL_checknumber(L, 2));
+ lua_pushnumber(L, input_state_info->last_height[signal_num]);
+ return 1;
+}
+
int Effect_set_float(lua_State *L)
{
assert(lua_gettop(L) == 3);
{ NULL, NULL }
};
+const luaL_Reg InputStateInfo_funcs[] = {
+ { "get_width", InputStateInfo_get_width },
+ { "get_height", InputStateInfo_get_height },
+ { NULL, NULL }
+};
+
} // namespace
LiveInputWrapper::LiveInputWrapper(Theme *theme, EffectChain *chain, bool override_bounce)
register_class("OverlayEffect", OverlayEffect_funcs);
register_class("ResizeEffect", ResizeEffect_funcs);
register_class("MixEffect", MixEffect_funcs);
+ register_class("InputStateInfo", InputStateInfo_funcs);
// Run script.
lua_settop(L, 0);
void Theme::register_class(const char *class_name, const luaL_Reg *funcs)
{
assert(lua_gettop(L) == 0);
- luaL_newmetatable(L, class_name);
+ luaL_newmetatable(L, class_name); // mt = {}
lua_pushlightuserdata(L, this);
- luaL_setfuncs(L, funcs, 1);
+ luaL_setfuncs(L, funcs, 1); // for (name,f in funcs) { mt[name] = f, with upvalue {theme} }
lua_pushvalue(L, -1);
- lua_setfield(L, -2, "__index");
- lua_setglobal(L, class_name);
+ lua_setfield(L, -2, "__index"); // mt.__index = mt
+ lua_setglobal(L, class_name); // ClassName = mt
assert(lua_gettop(L) == 0);
}
lua_pushnumber(L, t);
lua_pushnumber(L, width);
lua_pushnumber(L, height);
+ wrap_lua_object<InputStateInfo>(L, "InputStateInfo", input_state);
- if (lua_pcall(L, 4, 2, 0) != 0) {
+ if (lua_pcall(L, 5, 2, 0) != 0) {
fprintf(stderr, "error running function `get_chain': %s\n", lua_tostring(L, -1));
exit(1);
}