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

expose Pd's canvas_realizedollar() and modify set_args() for dollar arguments #54

Merged
merged 2 commits into from
Sep 21, 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
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