running metalua in a custom searcher

30 views
Skip to first unread message

David Manura

unread,
Nov 4, 2011, 12:06:59 AM11/4/11
to met...@googlegroups.com
I haven't liked how modules implemented in Metalua are not loadable in
the standard way via require on standard Lua interpreters as source
(i.e. without a separate compilation step done by hand to 5.1-specific
bytecode). However, one could invoke Metalua from a custom searcher
stuffed in package.loaders. Here's a rough (non-Metalua) example of
doing that type of thing in 5.2.0-beta:
https://gist.github.com/1338609 . Supporting this operating mode may
increase the acceptance of Metalua.

Fabien Fleutot

unread,
Nov 4, 2011, 5:07:48 AM11/4/11
to met...@googlegroups.com
On Fri, Nov 4, 2011 at 5:06 AM, David Manura <dm....@math2.org> wrote:
I haven't liked how modules implemented in Metalua are not loadable in
the standard way via require [...] However, one could invoke Metalua from a custom searcher
stuffed in package.loaders.

Not only can you, but it works by default. I've reimplemented package.findfile(), which was private in Lua 5.1 and is now public in 5.2, just so that the metalua loader can use it. Caveat: the metalua loader relies on LUA_MPATH / package.mpath instead of LUA_PATH / package.path, to avoid interfering with the plain Lua loader.

The ability to load precompiled bytecode exists in addition to the ability to compile *.mlua sources, and with a higher priority than loading from source, because loading metalua files can be arbitrarily long depending on how many meta-stages are needed. By precompiling standard libs into bytecode, they load just as fast as plain Lua, if not faster.

David Manura

unread,
Nov 4, 2011, 10:22:10 PM11/4/11
to met...@googlegroups.com
On Fri, Nov 4, 2011 at 5:07 AM, Fabien Fleutot <fle...@gmail.com> wrote:
> On Fri, Nov 4, 2011 at 5:06 AM, David Manura <dm....@math2.org> wrote:
>> one could invoke Metalua from a custom searcher stuffed in package.loaders.
> Not only can you, but it works by default.

I see :)

> Caveat: the metalua loader relies on LUA_MPATH / package.mpath
> instead of LUA_PATH / package.path

I'm a little bothered by the proliferation of path configuration (even
in standard Lua) just to make Lua find files in some local path. We
put path/?.so in LUA_CPATH and path/?.lua and path/?/init.lua in
LUA_PATH. Presumably we also now add path/?.luac and path/?/init.luac
to it as well. Then we append to LUA_MPATH for the .mlua files.

Reply all
Reply to author
Forward
0 new messages