Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow receiving messages on signal inlets, helpfile fix #43

Merged
merged 4 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions pdlua-help.pd
Original file line number Diff line number Diff line change
@@ -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:;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
20 changes: 18 additions & 2 deletions pdlua.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 *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 */
)
{
if(!argc) return;
pdlua_dispatch(p->owner, p->id, atom_getsymbol(argv), argc-1, argv+1);
}

/** Proxy inlet initialization. */
static void pdlua_proxyinlet_init
(
Expand All @@ -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, (t_method)pdlua_proxyinlet_fwd, gensym("fwd"), A_GIMME, 0);
}
}

/** Proxy receive 'anything' method. */
Expand Down Expand Up @@ -947,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))
Expand Down Expand Up @@ -1141,6 +1156,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))
{
Expand Down
Loading