aboutsummaryrefslogtreecommitdiff
path: root/src/pdlua.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/pdlua.c')
-rw-r--r--src/pdlua.c32
1 files changed, 30 insertions, 2 deletions
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