On 09/25/2015 03:04 PM, Hans Hagen wrote:
On 9/25/2015 4:09 PM, Orion Poplawski wrote:
I'm just starting to take a look how luatex makes use of lua. And it
appears that luatex does not merely use lua, but extends it in various
ways, essentially creating new lua dialect. Is the assessment correct?
Is there any documentation on this?
Indeed we have some more on board. Keep in mind that lua is used as
extension language so whenever it's used in an application there can be
extensions.
Btw, a dialect implies a different language. Adding a couple of
functions is not making it a dialect.
You appear to be extending it in at least four areas by adding new
functions, and replacing some as described below. liolibext is the most
"entangled" due to duplicating liolib code, lstrlibext also uses some
Lua internals that are not normally exposed to consumers of Lua (e.g.
lua_lock). I'm fine with not calling this a new "dialect", but it is
certainly extended, though modifying popen()/read()/lines() is
interesting. I'm interested to know if there has been any discussion
with the Lua maintainers about incorporating any of these changes in Lua
proper?
liolibext.c:
/* This extension only replaces one function: io.popen() and two
metatable entries: f:read() and f:lines() but unfortunately
it has to copy quite a bunch of lines from the original liolib.c
to do so.
*/
llfslibext.c: adds to lfs:
lua_setfield(L, -2, "isdir");
lua_pushcfunction(L, file_is_file);
lua_setfield(L, -2, "isfile");
lua_pushcfunction(L, read_link);
lua_setfield(L, -2, "readlink");
lua_pushcfunction(L, get_short_name);
lua_setfield(L, -2, "shortname");
loslibext.c:
lua_getglobal(L, "os");
lua_pushcfunction(L, ex_sleep);
lua_setfield(L, -2, "sleep");
lua_pushliteral(L, OS_PLATTYPE);
lua_setfield(L, -2, "type");
lua_pushliteral(L, OS_PLATNAME);
lua_setfield(L, -2, "name");
lua_pushcfunction(L, ex_uname);
lua_setfield(L, -2, "uname");
#if (! defined (_WIN32)) && (! defined (__SUNOS__))
lua_pushcfunction(L, os_times);
lua_setfield(L, -2, "times");
#endif
#if ! defined (__SUNOS__)
lua_pushcfunction(L, os_gettimeofday);
lua_setfield(L, -2, "gettimeofday");
#endif
if (!safer) {
lua_pushcfunction(L, os_setenv);
lua_setfield(L, -2, "setenv");
lua_pushcfunction(L, os_exec);
lua_setfield(L, -2, "exec");
lua_pushcfunction(L, os_spawn);
lua_setfield(L, -2, "spawn");
lua_pushcfunction(L, os_execute);
lua_setfield(L, -2, "execute");
lua_pushcfunction(L, os_tmpdir);
lua_setfield(L, -2, "tmpdir");
}
lstrlibext.c
{"utfvalues", str_utfvalues},
{"utfcharacters", str_utfcharacters},
{"characters", str_characters},
{"characterpairs", str_characterpairs},
{"bytes", str_bytes},
{"bytepairs", str_bytepairs},
{"explode", str_split},
{"dump", str_dump},
Also, is luajit used in the same way, or would it be possible to use a
system installed luajit in building luatex?
The only benefit of luajit is the faster virtual machine. A downside is
that there are some limitations in memory cq. stack usage. We use a
patch that makes the string hashing faster (we use the normal lua method
instead of the luajit one that is optimizied for urls and that can make
luajit slower than lua).
Becaus eluatex uses lua as extension language it will always be shipped
with a specific version (linked in or alongside the binary).
Hans
FWIW - Here are some changes I had to make while trying to compile
against lua 5.3:
diff --git a/texk/web2c/luatexdir/lua/liolibext.c
b/texk/web2c/luatexdir/lua/liolibext.c
index edf094d..883dce7 100644
--- a/texk/web2c/luatexdir/lua/liolibext.c
+++ b/texk/web2c/luatexdir/lua/liolibext.c
@@ -33,6 +33,7 @@
#include "lauxlib.h"
#endif
#include "lualib.h"
+#include <luaconf.h>
diff --git a/texk/web2c/luatexdir/lua/llualib.c
b/texk/web2c/luatexdir/lua/llualib.c
index 23bec6b..f0c4a21 100644
--- a/texk/web2c/luatexdir/lua/llualib.c
+++ b/texk/web2c/luatexdir/lua/llualib.c
@@ -258,7 +258,11 @@ static int set_bytecode(lua_State * L)
lua_bytecode_registers[k].buf = xmalloc(LOAD_BUF_SIZE);
lua_bytecode_registers[k].alloc = LOAD_BUF_SIZE;
memset(lua_bytecode_registers[k].buf, 0, LOAD_BUF_SIZE);
+#if LUA_VERSION_NUM >= 503
+ lua_dump(L, writer, (void *) (lua_bytecode_registers + k),0);
+#else
lua_dump(L, writer, (void *) (lua_bytecode_registers + k));
+#endif
}
lua_pop(L, 1);
return 0;
diff --git a/texk/web2c/luatexdir/lua/texluac.w
b/texk/web2c/luatexdir/lua/texluac.w
index 396121c..e533b8f 100644
--- a/texk/web2c/luatexdir/lua/texluac.w
+++ b/texk/web2c/luatexdir/lua/texluac.w
@@ -265,7 +265,11 @@ int luac_main(int ac, char *av[])
static void PrintString(const TString* ts)
{
const char* s=getstr(ts);
+#if LUA_VERSION_NUM >= 503
+ size_t i,n=ts->len;
+#else
size_t i,n=ts->tsv.len;
+#endif
printf("%c",'"');
for (i=0; i<n; i++)
{
@@ -305,7 +309,11 @@ static void PrintConstant(const Proto* f, int i)
printf(LUA_NUMBER_FMT,nvalue(o));
break;
case LUA_TSTRING:
+#if LUA_VERSION_NUM >= 503
PrintString(rawtsvalue(o));
+#else
+ PrintString(tsvalue(o));
+#endif
break;
default: /* cannot happen */
printf("? type=%d",ttype(o));
diff --git a/texk/web2c/luatexdir/slnunicode/slnunico.c
b/texk/web2c/luatexdir/slnunicode/slnunico.c
index 60ef95b..58e055e 100644
--- a/texk/web2c/luatexdir/slnunicode/slnunico.c
+++ b/texk/web2c/luatexdir/slnunicode/slnunico.c
@@ -435,7 +435,11 @@ static int str_dump (lua_State *L) {
luaL_checktype(L, 1, LUA_TFUNCTION);
lua_settop(L, 1);
luaL_buffinit(L,&b);
+#if LUA_VERSION_NUM >= 503
+ if (lua_dump(L, writer, &b, 0) != 0)
+#else
if (lua_dump(L, writer, &b) != 0)
+#endif
luaL_error(L, "unable to dump given function");
luaL_pushresult(&b);
return 1;
--
Orion Poplawski
Technical Manager 303-415-9701 x222
NWRA/CoRA Division FAX: 303-415-9702
3380 Mitchell Lane or...@cora.nwra.com
Boulder, CO 80301 http://www.cora.nwra.com
_______________________________________________
dev-luatex mailing list
dev-luatex@ntg.nl
http://www.ntg.nl/mailman/listinfo/dev-luatex