From ba8c0fa84e406ac7e2892db0591ffb60ae73d740 Mon Sep 17 00:00:00 2001 From: Timothy Schoen Date: Mon, 4 Mar 2024 03:12:09 +0100 Subject: [PATCH 1/4] Helpfile update --- pdlua-help.pd | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pdlua-help.pd b/pdlua-help.pd index feae98e..dcb133e 100644 --- a/pdlua-help.pd +++ b/pdlua-help.pd @@ -1,4 +1,4 @@ -#N canvas 466 36 560 603 10; +#N canvas 466 36 561 610 10; #X declare -lib pdlua -path pdlua; #X declare -path pdlua/examples; #X text 16 358 See also:; @@ -174,7 +174,7 @@ #X connect 111 0 65 0; #X connect 112 0 67 0; #X restore 446 359 pd quickstart; -#N canvas 106 35 1079 763 graphics 0; +#N canvas 106 35 1079 707 graphics 0; #X obj 8 77 hello-gui; #X text 8 376 function yourclass:initialize(sel \, atoms); #X text 24 409 return true; @@ -195,8 +195,8 @@ #X text 25 543 g:fill_all(); #X text 8 323 Graphics mode is enabled automatically by defining the paint method \, see below. You can also set the size in the constructor (or in any other function) \, like this:; #X text 23 394 self:set_size(100 \, 100); -#X text 373 818 -- Mouse down callback \, called when the mouse is clicked \; -- Mouse up callback \, called when the mouse button is released \; -- Mouse move callback \, called when the mouse is moved while not being down \; -- Mouse drag callback \, called when the mouse is moved while also being down \; \; -- Set object size \; -- Get object size \; \; -- Request a repaint \, after this the "paint" callback will occur \; -- Paint callback The argument "g" is the graphics context that you can call these drawing functions on: \; -- Sets the color for the next drawing operation. Colors are in range 0-255 \, optional alpha is in range 0-1 \; -- Draws a filled ellipse at the specified position and size. \; -- Draws the outline of an ellipse at the specified position and size. \; -- Draws a filled rectangle at the specified position and size. \; -- Draws the outline of a rectangle at the specified position and size. \; -- Draws a filled rounded rectangle at the specified position and size. \; -- Draws the outline of a rounded rectangle at the specified position and size. \; \; \; -- Draws a line between two points. \; -- Draws text at the specified position and size. \; \; -- Fills the entire drawing area with the current color. Also will draw an object outline in the style of the host (ie. pure-data or plugdata) \; \; -- Translates the coordinate system by the specified amounts. \; -- Scales the coordinate system by the specified factors. This will always happen after the translation \; -- Resets current scale and translation \; \; -- Initiates a new path at the specified point. \; -- Adds a line segment to the current path. \; -- Adds a quadratic Bezier curve to the current path. \; -- Adds a cubic Bezier curve to the current path. \; -- Closes the current path. \; \; -- Draws the outline of the current path with the specified line width. \; -- Fills the current path. \;, f 115; -#X text 8 816 pd:Class:mouse_down(x \, y) \; pd:Class:mouse_up(x \, y) \; pd:Class:mouse_move(x \, y) \; pd:Class:mouse_drag(x \, y) \; \; pd:Class:set_size(w \, h) \; width \, height = pd:Class:get_size() \; \; pd:Class:repaint() \; pd:Class:paint(g) \; \; g:set_color(r \, g \, b \, a=1.0) \; \; g:fill_ellipse(x \, y \, w \, h) \; g:stroke_ellipse(x \, y \, w \, h \, line_width) \; g:fill_rect(x \, y \, w \, h) \; g:stroke_rect(x \, y \, w \, h \, line_width) \; g:fill_rounded_rect(x \, y \, w \, h \, corner_radius) \; g:stroke_rounded_rect(x \, y \, w \, h \, corner_radius \, line_width) \; \; g:draw_line(x1 \, y1 \, x2 \, y2) \; g:draw_text(text \, x \, y \, w \, fontsize) \; \; g:fill_all() \; \; : g:translate(tx \, ty) \; g:scale(sx \, sy) \; g:reset_transform() \; \; p = path.start(x \, y) \; p:line_to(x \, y) \; p:quad_to(x1 \, y1 \, x2 \, y2) \; p:cubic_to(x1 \, y1 \, x2 \, y2 \, x3 \, y) \; p:close_path() \; \; g:stroke_path(p \, line_width) \; g:fill_path(p) \;, f 58; +#X text 8 816 pd:Class:mouse_down(x \, y) \; pd:Class:mouse_up(x \, y) \; pd:Class:mouse_move(x \, y) \; pd:Class:mouse_drag(x \, y) \; \; pd:Class:set_size(w \, h) \; width \, height = pd:Class:get_size() \; \; pd:Class:repaint() \; pd:Class:paint(g) \; \; g:set_color(r \, g \, b \, a=1.0) \; \; g:fill_ellipse(x \, y \, w \, h) \; g:stroke_ellipse(x \, y \, w \, h \, line_width) \; g:fill_rect(x \, y \, w \, h) \; g:stroke_rect(x \, y \, w \, h \, line_width) \; g:fill_rounded_rect(x \, y \, w \, h \, corner_radius) \; g:stroke_rounded_rect(x \, y \, w \, h \, corner_radius \, line_width) \; \; g:draw_line(x1 \, y1 \, x2 \, y2) \; g:draw_text(text \, x \, y \, w \, fontsize) \; \; g:fill_all() \; \; g:translate(tx \, ty) \; g:scale(sx \, sy) \; g:reset_transform() \; \; p = Path(x \, y) \; p:line_to(x \, y) \; p:quad_to(x1 \, y1 \, x2 \, y2) \; p:cubic_to(x1 \, y1 \, x2 \, y2 \, x3 \, y) \; p:close_path() \; \; g:stroke_path(p \, line_width) \; g:fill_path(p) \;, f 58; +#X text 373 818 -- Mouse down callback \, called when the mouse is clicked \; -- Mouse up callback \, called when the mouse button is released \; -- Mouse move callback \, called when the mouse is moved while not being down \; -- Mouse drag callback \, called when the mouse is moved while also being down \; \; -- Set object size \; -- Get object size \; \; -- Request a repaint \, after this the "paint" callback will occur \; -- Paint callback The argument "g" is the graphics context that you can call these drawing functions on: \; -- Sets the color for the next drawing operation. Colors are in range 0-255 \, optional alpha is in range 0-1 \; \; -- Draws a filled ellipse at the specified position and size. \; -- Draws the outline of an ellipse at the specified position and size. \; -- Draws a filled rectangle at the specified position and size. \; -- Draws the outline of a rectangle at the specified position and size. \; -- Draws a filled rounded rectangle at the specified position and size. \; -- Draws the outline of a rounded rectangle at the specified position and size. \; \; \; -- Draws a line between two points. \; -- Draws text at the specified position and size. \; \; -- Fills the entire drawing area with the current color. Also will draw an object outline in the style of the host (ie. pure-data or plugdata) \; \; -- Translates the coordinate system by the specified amounts. \; -- Scales the coordinate system by the specified factors. This will always happen after the translation \; -- Resets current scale and translation \; \; -- Initiates a new path at the specified point. \; -- Adds a line segment to the current path. \; -- Adds a quadratic Bezier curve to the current path. \; -- Adds a cubic Bezier curve to the current path. \; -- Closes the current path. \; \; -- Draws the outline of the current path with the specified line width. \; -- Fills the current path. \;, f 115; #X restore 446 409 pd graphics; #X text 324 384 Details on how to create GUI objects ------->, f 18; #X obj 342 227 hello; From d58ee89f8f3ad75a94049dd459f05fcccff70e5f Mon Sep 17 00:00:00 2001 From: Timothy Schoen Date: Mon, 4 Mar 2024 03:54:46 +0100 Subject: [PATCH 2/4] Also allow receiving messages on signal inlets --- pdlua.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/pdlua.c b/pdlua.c index 6657923..6af61c4 100644 --- a/pdlua.c +++ b/pdlua.c @@ -363,6 +363,18 @@ static void pdlua_proxyinlet_anything pdlua_dispatch(p->owner, p->id, s, argc, argv); } +static void pdlua_proxyinlet_fwd +( + t_pdlua_proxyinlet *p, /**< The proxy inlet that received the message. */ + t_symbol *s, /**< The message selector, which is always "fwd" */ + int argc, /**< The message length. */ + t_atom *argv /**< The atoms in the message. The first atom is the actual selector */ +) +{ + if(!argc) return; + pdlua_dispatch(p->owner, p->id, atom_getsymbol(argv), argc-1, argv+1); +} + /** Proxy inlet initialization. */ static void pdlua_proxyinlet_init ( @@ -380,8 +392,10 @@ static void pdlua_proxyinlet_init static void pdlua_proxyinlet_setup(void) { pdlua_proxyinlet_class = class_new(gensym("pdlua proxy inlet"), 0, 0, sizeof(t_pdlua_proxyinlet), 0, 0); - if (pdlua_proxyinlet_class) + if (pdlua_proxyinlet_class) { class_addanything(pdlua_proxyinlet_class, pdlua_proxyinlet_anything); + class_addmethod(pdlua_proxyinlet_class, pdlua_proxyinlet_fwd, gensym("fwd"), A_GIMME, 0); + } } /** Proxy receive 'anything' method. */ @@ -1141,6 +1155,7 @@ static int pdlua_object_createinlets(lua_State *L) * \li \c 2 Number of inlets. * */ { + PDLUA_DEBUG("pdlua_object_createinlets: stack top is %d", lua_gettop(L)); if (lua_islightuserdata(L, 1)) { From 46f9eaee33ba77b19fa8e5207381e47d4f4ba203 Mon Sep 17 00:00:00 2001 From: Timothy Schoen Date: Mon, 4 Mar 2024 13:36:57 +0100 Subject: [PATCH 3/4] Fixed segfault when perform() function call fails --- pdlua.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pdlua.c b/pdlua.c index 6af61c4..4eca4f9 100644 --- a/pdlua.c +++ b/pdlua.c @@ -961,7 +961,8 @@ static t_int *pdlua_perform(t_int *w){ if (lua_pcall(__L(), 1 + o->siginlets, o->sigoutlets, 0)) { pd_error(o, "pdlua: error in perform:\n%s", lua_tostring(__L(), -1)); - lua_pop(__L(), 1); /* pop the error string */ + lua_pop(__L(), 2); /* pop the error string and global pd */ + return w + o->siginlets + o->sigoutlets + 3; } if (!lua_istable(__L(), -1)) From 998d11fdf17e8675cb0b8186dfcce55fda443128 Mon Sep 17 00:00:00 2001 From: Timothy Schoen Date: Mon, 4 Mar 2024 14:22:38 +0100 Subject: [PATCH 4/4] Fixed new warnings --- pdlua.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pdlua.c b/pdlua.c index 4eca4f9..5656b89 100644 --- a/pdlua.c +++ b/pdlua.c @@ -366,7 +366,7 @@ static void pdlua_proxyinlet_anything static void pdlua_proxyinlet_fwd ( t_pdlua_proxyinlet *p, /**< The proxy inlet that received the message. */ - t_symbol *s, /**< The message selector, which is always "fwd" */ + t_symbol *UNUSED(s), /**< The message selector, which is always "fwd" */ int argc, /**< The message length. */ t_atom *argv /**< The atoms in the message. The first atom is the actual selector */ ) @@ -394,7 +394,7 @@ static void pdlua_proxyinlet_setup(void) pdlua_proxyinlet_class = class_new(gensym("pdlua proxy inlet"), 0, 0, sizeof(t_pdlua_proxyinlet), 0, 0); if (pdlua_proxyinlet_class) { class_addanything(pdlua_proxyinlet_class, pdlua_proxyinlet_anything); - class_addmethod(pdlua_proxyinlet_class, pdlua_proxyinlet_fwd, gensym("fwd"), A_GIMME, 0); + class_addmethod(pdlua_proxyinlet_class, (t_method)pdlua_proxyinlet_fwd, gensym("fwd"), A_GIMME, 0); } }