Skip to content
Open
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
2 changes: 1 addition & 1 deletion pd.lua
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ pd._constructor = function (name, atoms)
if nil ~= pd._classes[fullpath] then
local o = pd._classes[fullpath]:new():construct(name, atoms)
if o then
pd._objects[o._object] = o
return o._object
end
end
Expand Down Expand Up @@ -360,6 +359,7 @@ function pd.Class:construct(sel, atoms)
if self:initialize(sel, atoms) then
pd._createinlets(self._object, self.inlets)
pd._createoutlets(self._object, self.outlets)
pd._objects[self._object] = self
if type(self.paint) == "function" then
pd._creategui(self._object)
end
Expand Down
12 changes: 12 additions & 0 deletions pdlua.c
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,11 @@ static void pdlua_proxyinlet_anything
t_atom *argv /**< The atoms in the message. */
)
{
#ifdef WEBPDL2ORK
if(s == gensym("mouse_event"))
pdlua_gfx_mouse_event(p->owner, atom_getint(&argv[0]), atom_getint(&argv[1]), atom_getint(&argv[2]));
else
#endif
pdlua_dispatch(p->owner, p->id, s, argc, argv);
}

Expand Down Expand Up @@ -1458,6 +1463,13 @@ static int pdlua_object_new(lua_State *L)
// NULL until plugdata overrides them with something useful
o->gfx.plugdata_draw_callback = NULL;
#endif
#ifdef WEBPDL2ORK
static int next_lua_id = 0;
if(strcmp(c->c_name->s_name, "pdlua") && strcmp(c->c_name->s_name, "pdluax"))
o->lua_id = ++next_lua_id;
else
o->lua_id = 0;
#endif

lua_pushlightuserdata(L, o);
PDLUA_DEBUG("pdlua_object_new: success end. stack top is %d", lua_gettop(L));
Expand Down
3 changes: 3 additions & 0 deletions pdlua.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ typedef struct pdlua
t_class *pdlua_class; // Holds our class pointer.
t_class *pdlua_class_gfx; // Holds our gfx class pointer.
t_signal **sp; // Array of signal pointers for multichannel audio.
#ifdef WEBPDL2ORK
int lua_id; // ID for WebPDL2ORK to track this object
#endif
} t_pdlua;

lua_State* __L();
30 changes: 30 additions & 0 deletions pdlua_gfx.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,28 @@

#ifdef PURR_DATA

// Compatibility with WebPdL2Ork. WebPdL2Ork receives data in a slightly
// different way (via messages, rather than gui sockets). These macros
// adapt the vmesses used in this file to work with WebPdL2Ork with
// minimal disruption.
#ifdef WEBPDL2ORK
#include "webvmess.h"
const char* pdlua_resolve_vmess(void *x) {
t_pdlua *obj = (t_pdlua*)x;
const char* result = calloc(10, sizeof(char));
sprintf(result, "lua_%d", obj->lua_id);

return result;
}

static void *obj = NULL;
#define gui_vmess(...) webpdl2ork_vmess(obj, &pdlua_resolve_vmess, __VA_ARGS__)
#define gui_start_vmess webpdl2ork_start_vmess
#define gui_s webpdl2ork_s
#define gui_f webpdl2ork_f
#define gui_end_vmess() webpdl2ork_end_vmess(obj, &pdlua_resolve_vmess)
#endif

// Port of the vanilla gfx interface to Purr Data. There are some differences
// in the zoom API which Purr Data does directly on the canvas, so we can just
// always assume a zoom factor of 1. Other API differences are dealt with on
Expand Down Expand Up @@ -1582,3 +1604,11 @@ static int free_path(lua_State* L)
freebytes(path->path_segments, path->num_path_segments_allocated * sizeof(int));
return 0;
}

#ifdef WEBPDL2ORK
#undef gui_vmess
#undef gui_start_vmess
#undef gui_s
#undef gui_f
#undef gui_end_vmess
#endif