aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMartin Peach <mrpeach@users.sourceforge.net>2011-09-22 20:55:40 +0000
committerIOhannes m zmölnig <zmoelnig@iem.at>2015-10-14 14:28:31 +0200
commite6478d5a3b758a7cb13070c1d893d91ea15296fd (patch)
tree6803cc82df54aa4757a43d384cb363f9395d20f1 /src
parent571ef7da9be59610db260788ebe07bb8ec5b95fe (diff)
Use pdlua_proxy_inlet_class->c_externdir->s_name as pd.lua's directory instead of canvas_open.
Downside: This requires m_imp.h, which is supposed to be secret... Thanks hcs for pointing this out. svn path=/trunk/externals/loaders/pdlua/; revision=15342
Diffstat (limited to 'src')
-rw-r--r--src/pdlua.c23
1 files changed, 17 insertions, 6 deletions
diff --git a/src/pdlua.c b/src/pdlua.c
index 42bfa9a..b80215c 100644
--- a/src/pdlua.c
+++ b/src/pdlua.c
@@ -28,6 +28,9 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <sys/types.h> // for open
+#include <sys/stat.h> // for open
+#include <sys/fcntl.h> // for open
#ifdef _MSC_VER
#include <io.h>
#define read _read
@@ -44,6 +47,7 @@
/* we use Pd */
#include "m_pd.h"
#include "s_stuff.h" // for sys_register_loader()
+#include "m_imp.h" // for struct _class
#ifdef _MSC_VER
#include <s_stuff.h>
#endif
@@ -97,7 +101,7 @@
/* EVIL: end of evil section. */
/* If defined, PDLUA_DEBUG lets pdlua post a lot of text */
-// #define PDLUA_DEBUG
+//#define PDLUA_DEBUG
/** Global Lua interpreter state, needed in the constructor. */
static lua_State *L;
@@ -1348,8 +1352,7 @@ static int pdlua_loader
/** Start the Lua runtime and register our loader hook. */
EXTERN void pdlua_setup(void)
{
- char buf[MAXPDSTRING];
- char *ptr;
+ char pd_lua_path[MAXPDSTRING];
t_pdlua_readerdata reader;
int fd;
int result;
@@ -1382,13 +1385,21 @@ EXTERN void pdlua_setup(void)
post("pdlua pdlua_init done");
#endif // PDLUA_DEBUG
/* "pd.lua" is the Lua part of pdlua, want to keep the C part minimal */
- fd = canvas_open(0, "pd", ".lua", buf, &ptr, MAXPDSTRING, 1);
+ /* canvas_open can't find pd.lua unless we give the path to pd beforehand like pd -path /usr/lib/extra/pdlua */
+ /* To avoid this we can use c_externdir from m_imp.h, struct _class: t_symbol *c_externdir; */
+ /* c_externdir is the directory the extern was loaded from and is also the directory contining pd.lua */
+ sprintf(pd_lua_path, "%s/pd.lua", pdlua_proxyinlet_class->c_externdir->s_name); /* the full path to pd.lua */
#ifdef PDLUA_DEBUG
- post ("pd.lua loaded from %s", buf);
+ post("pd_lua_path %s", pd_lua_path);
+#endif // PDLUA_DEBUG
+ fd = open(pd_lua_path, O_RDONLY);
+/* fd = canvas_open(canvas_getcurrent(), "pd", ".lua", buf, &ptr, MAXPDSTRING, 1); looks all over and rarely succeeds */
+#ifdef PDLUA_DEBUG
+ post ("pd.lua loaded from %s", pd_lua_path);
post("pdlua canvas_open done fd = %d", fd);
#endif // PDLUA_DEBUG
if (fd >= 0)
- {
+ { /* pd.lua was opened */
reader.fd = fd;
result = lua_load(L, pdlua_reader, &reader, "pd.lua");
#ifdef PDLUA_DEBUG