diff options
author | Martin Peach <mrpeach@users.sourceforge.net> | 2014-01-06 19:04:59 +0000 |
---|---|---|
committer | IOhannes m zmölnig <zmoelnig@iem.at> | 2015-10-14 14:28:31 +0200 |
commit | 349e81ecd8ec307c187c0ff4abf0788f381a3087 (patch) | |
tree | f7786e4867712c510dcec424c5d7533b66a67af6 /src/pdlua.c | |
parent | df3c5bae24837b144a1f09d06d4cad90b8905915 (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
Diffstat (limited to 'src/pdlua.c')
-rw-r--r-- | src/pdlua.c | 32 |
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
|