Embed extra search paths into Lua build?

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Embed extra search paths into Lua build?

Christopher Tallman
Is there an easy way to build Lua with additional package search
paths? I searched and didn't see any compile-time way to add in extra
paths to the defaults apart from explicitly editing luaconf.h.

Ideally, I would be able to add in a preprocessor definition like
-DLUA_PATH_EXTRA="./modules/?.lua" when compiling and wouldn't have to
change the actual source (so we can keep the same build process for
subsequent versions).

Is something like this already provided? Am I stuck with changing
LUA_PATH_DEFAULT and LUA_CPATH_DEFAULT in luaconf.h?

Thank you

Reply | Threaded
Open this post in threaded view
|

Re: Embed extra search paths into Lua build?

Sean Conner
It was thus said that the Great Christopher Tallman once stated:

> Is there an easy way to build Lua with additional package search
> paths? I searched and didn't see any compile-time way to add in extra
> paths to the defaults apart from explicitly editing luaconf.h.
>
> Ideally, I would be able to add in a preprocessor definition like
> -DLUA_PATH_EXTRA="./modules/?.lua" when compiling and wouldn't have to
> change the actual source (so we can keep the same build process for
> subsequent versions).
>
> Is something like this already provided? Am I stuck with changing
> LUA_PATH_DEFAULT and LUA_CPATH_DEFAULT in luaconf.h?

  There are the environment variables LUA_PATH and LUA_CPATH that can be
used to modify the search paths.

  -spc


Reply | Threaded
Open this post in threaded view
|

Re: Embed extra search paths into Lua build?

Luiz Henrique de Figueiredo
In reply to this post by Christopher Tallman
> Ideally, I would be able to add in a preprocessor definition like
> -DLUA_PATH_EXTRA="./modules/?.lua" when compiling and wouldn't have to
> change the actual source (so we can keep the same build process for
> subsequent versions).
>
> Is something like this already provided? Am I stuck with changing
> LUA_PATH_DEFAULT and LUA_CPATH_DEFAULT in luaconf.h?

You can write your definitions in a file, say mydefs.h, and then
build Lua with -DLUA_USER_H='"mydefs.h"'.

In mydefs.h, you need to do

#undef LUA_PATH_DEFAULT
#define LUA_PATH_DEFAULT ...

#undef LUA_CPATH_DEFAULT
#define LUA_CPATH_DEFAULT ...

If you're using the Makefile in the source distribution, you can say
something like
        make linux MYCFLAGS='-DLUA_USER_H='"'"'"mydefs.h"'"'"

Yes, it's a mess of quotes because one layer is stripped by the shell,
another by make, another by the shell that makes invokes, etc...

Reply | Threaded
Open this post in threaded view
|

Re: Embed extra search paths into Lua build?

Brigham Toskin
In reply to this post by Sean Conner
On Sat, Jul 11, 2015 at 11:11 AM, Sean Conner <[hidden email]> wrote:
It was thus said that the Great Christopher Tallman once stated:
> Is there an easy way to build Lua with additional package search
> paths? I searched and didn't see any compile-time way to add in extra
> paths to the defaults apart from explicitly editing luaconf.h.
>
> Ideally, I would be able to add in a preprocessor definition like
> -DLUA_PATH_EXTRA="./modules/?.lua" when compiling and wouldn't have to
> change the actual source (so we can keep the same build process for
> subsequent versions).
>
> Is something like this already provided? Am I stuck with changing
> LUA_PATH_DEFAULT and LUA_CPATH_DEFAULT in luaconf.h?

  There are the environment variables LUA_PATH and LUA_CPATH that can be
used to modify the search paths.

It seems to me that this kind of thing is exactly the kind of thing that luaconf.h is there for; don't be afraid to hack it. It was never meant to be the canonical source of Universal Truth across all Lua builds everywhere. You want to build a custom configuration, so you have to customize the configuration.

--
Brigham Toskin
Reply | Threaded
Open this post in threaded view
|

Re: Embed extra search paths into Lua build?

Roberto Ierusalimschy
> It seems to me that this kind of thing is exactly the kind of thing that
> luaconf.h is there for; don't be afraid to hack it. It was never meant to
> be the canonical source of Universal Truth across all Lua builds
> everywhere. You want to build a custom configuration, so you have to
> customize the configuration.

Right. 'luaconf.h' is there to be edited for configuration (see its
comments).

If you want, you can make your changes at the end of the file, by
unedefining and then redefining what you need (see last comments
in 'luaconf.h').

-- Roberto

Reply | Threaded
Open this post in threaded view
|

Re: Embed extra search paths into Lua build?

Christopher Tallman
On Sat, Jul 11, 2015 at 2:39 PM, Roberto Ierusalimschy
<[hidden email]> wrote:

>> It seems to me that this kind of thing is exactly the kind of thing that
>> luaconf.h is there for; don't be afraid to hack it. It was never meant to
>> be the canonical source of Universal Truth across all Lua builds
>> everywhere. You want to build a custom configuration, so you have to
>> customize the configuration.
>
> Right. 'luaconf.h' is there to be edited for configuration (see its
> comments).
>
> If you want, you can make your changes at the end of the file, by
> unedefining and then redefining what you need (see last comments
> in 'luaconf.h').
>
> -- Roberto
>

Thank you for the help. I really appreciate the breadth of options. :)

We have a build process that builds several Lua versions from source,
so it was nice to think there might have been a way to update our
build script and propagate the changes to each built version.

I think as long as I document my changes to luaconf.h appropriately,
everything will be fine; I'll just have to remember to make the same
update to whatever Lua version comes next.

Thanks!

Reply | Threaded
Open this post in threaded view
|

Re: Embed extra search paths into Lua build?

Coda Highland
On Sun, Jul 12, 2015 at 8:53 AM, Christopher Tallman
<[hidden email]> wrote:

> On Sat, Jul 11, 2015 at 2:39 PM, Roberto Ierusalimschy
> <[hidden email]> wrote:
>>> It seems to me that this kind of thing is exactly the kind of thing that
>>> luaconf.h is there for; don't be afraid to hack it. It was never meant to
>>> be the canonical source of Universal Truth across all Lua builds
>>> everywhere. You want to build a custom configuration, so you have to
>>> customize the configuration.
>>
>> Right. 'luaconf.h' is there to be edited for configuration (see its
>> comments).
>>
>> If you want, you can make your changes at the end of the file, by
>> unedefining and then redefining what you need (see last comments
>> in 'luaconf.h').
>>
>> -- Roberto
>>
>
> Thank you for the help. I really appreciate the breadth of options. :)
>
> We have a build process that builds several Lua versions from source,
> so it was nice to think there might have been a way to update our
> build script and propagate the changes to each built version.
>
> I think as long as I document my changes to luaconf.h appropriately,
> everything will be fine; I'll just have to remember to make the same
> update to whatever Lua version comes next.
>
> Thanks!
>

Consider creating a patch file that makes the changes to luaconf.h
from a clean Lua source tree, and apply it automatically. Then you
only have to worry about it if the patch fails, and that'll be a
visible failure in your build process.

/s/ Adam

Reply | Threaded
Open this post in threaded view
|

Re: Embed extra search paths into Lua build?

William Ahern
In reply to this post by Luiz Henrique de Figueiredo
On Sat, Jul 11, 2015 at 05:37:28PM -0300, Luiz Henrique de Figueiredo wrote:

> > Ideally, I would be able to add in a preprocessor definition like
> > -DLUA_PATH_EXTRA="./modules/?.lua" when compiling and wouldn't have to
> > change the actual source (so we can keep the same build process for
> > subsequent versions).
> >
> > Is something like this already provided? Am I stuck with changing
> > LUA_PATH_DEFAULT and LUA_CPATH_DEFAULT in luaconf.h?
>
> You can write your definitions in a file, say mydefs.h, and then
> build Lua with -DLUA_USER_H='"mydefs.h"'.
>

I can't believe I missed this feature all these years. I'm embarrassed for
myself.


Reply | Threaded
Open this post in threaded view
|

Re: Embed extra search paths into Lua build?

Luiz Henrique de Figueiredo
> > You can write your definitions in a file, say mydefs.h, and then
> > build Lua with -DLUA_USER_H='"mydefs.h"'.
>
> I can't believe I missed this feature all these years.

For the record, support for LUA_USER_H was introduced in Lua 5.0.