diff --git a/pd.lua b/pd.lua index 28b5dd1..1a2171e 100644 --- a/pd.lua +++ b/pd.lua @@ -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 @@ -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 diff --git a/pdlua.c b/pdlua.c index 562340d..59ccd60 100644 --- a/pdlua.c +++ b/pdlua.c @@ -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); } @@ -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)); diff --git a/pdlua.h b/pdlua.h index 0b2f24a..7e12c83 100644 --- a/pdlua.h +++ b/pdlua.h @@ -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(); diff --git a/pdlua_gfx.h b/pdlua_gfx.h index a3f32ab..00ee137 100644 --- a/pdlua_gfx.h +++ b/pdlua_gfx.h @@ -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 @@ -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 \ No newline at end of file