aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Peach <mrpeach@users.sourceforge.net>2014-01-06 19:04:59 +0000
committerIOhannes m zmölnig <zmoelnig@iem.at>2015-10-14 14:28:31 +0200
commit349e81ecd8ec307c187c0ff4abf0788f381a3087 (patch)
treef7786e4867712c510dcec424c5d7533b66a67af6
parentdf3c5bae24837b144a1f09d06d4cad90b8905915 (diff)
Removed references to lua5.1, now pdlua.c compiles for whichever lua is found, based on LUA_VERSION_NUM from lua.h.
Prints lua version according to lua_version() to console on startup. Modified some function calls for the 5.2 API. svn path=/trunk/externals/loaders/pdlua/; revision=17235
-rw-r--r--src/Makefile4
-rw-r--r--src/pdlua.c32
2 files changed, 32 insertions, 4 deletions
diff --git a/src/Makefile b/src/Makefile
index ed7ae23..0eeb387 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -151,8 +151,8 @@ ifeq ($(UNAME),Linux)
OPT_CFLAGS = -O6 -funroll-loops -fomit-frame-pointer
CFLAGS += -fPIC -threepic
LDFLAGS += -Wl,--export-dynamic -shared -fPIC
- LUACFLAGS += -I/usr/include/lua5.1 # lua is named differently on every platform, check this and change it to fit
- LIBS += -llua5.1 # lua is named differently on every platform, check this and change it to fit
+ LUACFLAGS += -I/usr/include/lua # lua is named differently on every platform, check this and change it to fit
+ LIBS += -llua # lua is named differently on every platform, check this and change it to fit
LIBS += -lc
STRIP = strip --strip-unneeded -R .note -R .comment
DISTBINDIR=$(DISTDIR)-$(OS)-$(shell uname -m)
diff --git a/src/pdlua.c b/src/pdlua.c
index e802566..7feb382 100644
--- a/src/pdlua.c
+++ b/src/pdlua.c
@@ -1056,7 +1056,11 @@ static t_atom *pdlua_popatomtable
#endif // PDLUA_DEBUG
if (lua_istable(L, -1))
{
+#if LUA_VERSION_NUM < 502
*count = lua_objlen(L, -1);
+#else // 5.2 style
+ *count = lua_rawlen(L, -1);
+#endif // LUA_VERSION_NUM < 502
if (*count > 0) atoms = malloc(*count * sizeof(t_atom));
i = 0;
lua_pushnil(L);
@@ -1555,7 +1559,11 @@ static int pdlua_dofile(lua_State *L)
//pdlua_setpathname(o, buf);/* change the scriptname to include its path */
pdlua_setrequirepath(L, buf);
reader.fd = fd;
+#if LUA_VERSION_NUM < 502
if (lua_load(L, pdlua_reader, &reader, filename))
+#else // 5.2 style
+ if (lua_load(L, pdlua_reader, &reader, filename, NULL))
+#endif // LUA_VERSION_NUM < 502
{
close(fd);
pdlua_clearrequirepath(L);
@@ -1701,7 +1709,11 @@ static int pdlua_loader
class_set_extern_dir(gensym(dirbuf));
pdlua_setrequirepath(L, dirbuf);
reader.fd = fd;
+#if LUA_VERSION_NUM < 502
if (lua_load(L, pdlua_reader, &reader, name) || lua_pcall(L, 0, 0, 0))
+#else // 5.2 style
+ if (lua_load(L, pdlua_reader, &reader, name, NULL) || lua_pcall(L, 0, 0, 0))
+#endif // LUA_VERSION_NUM < 502
{
error("lua: error loading `%s':\n%s", name, lua_tostring(L, -1));
@@ -1738,22 +1750,30 @@ void pdlua_setup(void)
t_pdlua_readerdata reader;
int fd;
int result;
- char* pdluaver = "pdlua 0.7.1 (GPL) 2012 Martin Peach, based on";
+ char* pdluaver = "pdlua 0.7.2 (GPL) 2014 Martin Peach, based on";
char* luaver = "lua 0.6~svn (GPL) 2008 Claude Heiland-Allen <claudiusmaximus@goto10.org>";
char compiled[MAXPDSTRING];
+ char luaversionStr[MAXPDSTRING];
+ const lua_Number *luaversion = lua_version (NULL);
+ int lvm, lvl;
- snprintf(compiled, MAXPDSTRING, "pdlua: compiled for pd-%d.%d on %s %s",
+ snprintf(compiled, MAXPDSTRING-1, "pdlua: compiled for pd-%d.%d on %s %s",
PD_MAJOR_VERSION, PD_MINOR_VERSION, __DATE__, __TIME__);
+ lvm = (*luaversion)/100;
+ lvl = (*luaversion) - (100*lvm);
+ snprintf(luaversionStr, MAXPDSTRING-1, "Using lua version %d.%d", lvm, lvl);
#if PD_MAJOR_VERSION==0 && PD_MINOR_VERSION<43
post(pdluaver);
post(luaver);
post(compiled);
+ post(luaversionStr);
#else
logpost(NULL, 3, pdluaver);
logpost(NULL, 3, luaver);
logpost(NULL, 3, compiled);
+ logpost(NULL, 3, luaversionStr);
#endif
pdlua_proxyinlet_setup();
#ifdef PDLUA_DEBUG
@@ -1767,7 +1787,11 @@ void pdlua_setup(void)
#ifdef PDLUA_DEBUG
post("pdlua pdlua_proxyclock_setup done");
#endif // PDLUA_DEBUG
+#if LUA_VERSION_NUM < 502
L = lua_open();
+#else // 5.2 style
+ L = luaL_newstate();
+#endif // LUA_VERSION_NUM < 502
#ifdef PDLUA_DEBUG
post("pdlua lua_open done L = %p", L);
#endif // PDLUA_DEBUG
@@ -1797,7 +1821,11 @@ void pdlua_setup(void)
if (fd >= 0)
{ /* pd.lua was opened */
reader.fd = fd;
+#if LUA_VERSION_NUM < 502
result = lua_load(L, pdlua_reader, &reader, "pd.lua");
+#else // 5.2 style
+ result = lua_load(L, pdlua_reader, &reader, "pd.lua", NULL); // mode bt for binary or text
+#endif // LUA_VERSION_NUM < 502
#ifdef PDLUA_DEBUG
post ("pdlua lua_load returned %d", result);
#endif // PDLUA_DEBUG