Skip to content

Commit

Permalink
Merge pull request #54 from ben-wes/feature/realizedollar
Browse files Browse the repository at this point in the history
expose Pd's canvas_realizedollar() and modify set_args() for dollar arguments
  • Loading branch information
agraef authored Sep 21, 2024
2 parents 4c8c8b6 + 48f0053 commit 2a6dda2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
4 changes: 4 additions & 0 deletions pd.lua
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,10 @@ function pd.Class:set_args(args)
pd._set_args(self._object, args)
end

function pd.Class:canvas_realizedollar(s)
return pd._canvas_realizedollar(self._object, s)
end

function pd.Class:repaint()
if type(self.paint) == "function" then
local g = _gfx_internal.start_paint(self._object);
Expand Down
29 changes: 25 additions & 4 deletions pdlua.c
Original file line number Diff line number Diff line change
Expand Up @@ -1184,11 +1184,12 @@ static int pdlua_set_arguments(lua_State *L)
binbuf_add(b, 1, &atom);
}
else if (lua_isstring(L, -1)) {
// If it's a string, convert it to a symbol and add to binbuf
// If it's a string, parse it using binbuf_text and add the resulting atoms to the binbuf
const char* str = lua_tostring(L, -1);
t_atom atom;
SETSYMBOL(&atom, gensym(str));
binbuf_add(b, 1, &atom);
t_binbuf *temp = binbuf_new();
binbuf_text(temp, str, strlen(str));
binbuf_add(b, binbuf_getnatom(temp), binbuf_getvec(temp));
binbuf_free(temp);
}

// Pop the value from the stack
Expand Down Expand Up @@ -2490,6 +2491,23 @@ static int pdlua_dofile(lua_State *L)
return lua_gettop(L) - n;
}

static int pdlua_canvas_realizedollar(lua_State *L)
{
if (lua_islightuserdata(L, 1) && lua_isstring(L, 2))
{
t_pdlua *o = lua_touserdata(L, 1);
if (o && o->canvas)
{
const char *sym_name = lua_tostring(L, 2);
t_symbol *s = gensym(sym_name);
t_symbol *result = canvas_realizedollar(o->canvas, s);
lua_pushstring(L, result->s_name);
return 1;
}
}
return 0;
}

/** Initialize the pd API for Lua. */
static void pdlua_init(lua_State *L)
/**< Lua interpreter state. */
Expand Down Expand Up @@ -2585,6 +2603,9 @@ static void pdlua_init(lua_State *L)
lua_pushstring(L, "_set_args");
lua_pushcfunction(L, pdlua_set_arguments);
lua_settable(L, -3);
lua_pushstring(L, "_canvas_realizedollar");
lua_pushcfunction(L, pdlua_canvas_realizedollar);
lua_settable(L, -3);
lua_pushstring(L, "_error");
lua_pushcfunction(L, pdlua_error);
lua_settable(L, -3);
Expand Down

0 comments on commit 2a6dda2

Please sign in to comment.