Supports Lua Includefiles?

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

Supports Lua Includefiles?

Thomas Pototschnig
Hi all,
 
does Lua support includefiles for often used parts of a programm, but in different programms, like a header file in C?
 
 
 
thanks for reply
 
 
Thomas Pototschnig
Reply | Threaded
Open this post in threaded view
|

Re: Supports Lua Includefiles?

Luiz Henrique de Figueiredo
>does Lua support includefiles for often used parts of a programm, but in
>different programms, like a header file in C?

Simply add dofile"myfuncs.lua" at the beginning of your file.

Lua 4.1 will have a function "require" that will avoid loading the same file
twice.
--lhf

Reply | Threaded
Open this post in threaded view
|

RE: Supports Lua Includefiles?

Luiz Henrique de Figueiredo
>I'm really looking forward to 4.1!!

If you mean because of "require", then you don't have to wait, because the
implementatin simply uses the registry to keep track of which files have been
loaded.

You can do something similar in Lua by redefining "dofile":

local A={}
function dofile(x)
 if %A[x]==nil then %A[x]=1; return %dofile(x) end
end

--lhf

Reply | Threaded
Open this post in threaded view
|

RE: Supports Lua Includefiles?

Pete Gardner
I'm really looking forward to 4.1!!
:)

Pete Gardner
President, CEO
Helikon Technologies Inc.
http://www.helikon.com




> -----Original Message-----
> From: Luiz Henrique de Figueiredo [[hidden email]]
> Sent: Tuesday, April 10, 2001 9:05 AM
> To: Multiple recipients of list
> Subject: Re: Supports Lua Includefiles?
> 
> 
> >does Lua support includefiles for often used parts of a 
> programm, but in
> >different programms, like a header file in C?
> 
> Simply add dofile"myfuncs.lua" at the beginning of your file.
> 
> Lua 4.1 will have a function "require" that will avoid 
> loading the same file
> twice.
> --lhf
> 

Reply | Threaded
Open this post in threaded view
|

RE: Supports Lua Includefiles?

Pete Gardner
In reply to this post by Luiz Henrique de Figueiredo


> 
> If you mean because of "require", then you don't have to 
> wait, because the
> implementatin simply uses the registry to keep track of which 
> files have been
> loaded.
> 
> You can do something similar in Lua by redefining "dofile":
> 
> local A={}
> function dofile(x)
>  if %A[x]==nil then %A[x]=1; return %dofile(x) end
> end
> 
> --lhf

This language just amazes me!  I must commend Luiz and the whole Lua team on
their efforts.  Although I am new to Lua, I can see clearly that it has the
potential to seriously change the face of programming as we know it.  My
hat's off to you all!  :)

Pete Gardner
President, CEO
Helikon Technologies Inc.
http://www.helikon.com

 

Reply | Threaded
Open this post in threaded view
|

Re: Supports Lua Includefiles?

Christian Vogler-2
In reply to this post by Luiz Henrique de Figueiredo
On Tue, Apr 10, 2001 at 01:04:42PM -0300, Luiz Henrique de Figueiredo wrote:
> >does Lua support includefiles for often used parts of a programm, but in
> >different programms, like a header file in C?
> 
> Simply add dofile"myfuncs.lua" at the beginning of your file.
> 
> Lua 4.1 will have a function "require" that will avoid loading the same file
> twice.

Will there also be the possibility of specifying the paths to search
in some environment variable, analogous to the PATH variable, for
example? This is pretty much necessary in order to create reusable
libraries that reside somewhere else on the system as part of a
standard installation.

I've written some code for lua 3.2 and lua 4.0 that does this and also
what require will do. It searches the current directory first, and
then the environment variable LUA_SCRIPT_PATH. It would be nice if
this functionality were part of the standard behavior of lua.

- Christian

Reply | Threaded
Open this post in threaded view
|

Re: Supports Lua Includefiles?

Luiz Henrique de Figueiredo
In reply to this post by Luiz Henrique de Figueiredo
>Will there also be the possibility of specifying the paths to search
>in some environment variable, analogous to the PATH variable

Yes, "require" will be exactly like this. I forgot to mention.
--lhf

Reply | Threaded
Open this post in threaded view
|

Re: Supports Lua Includefiles?

Michael T. Richter-2
In reply to this post by Christian Vogler-2
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

> I've written some code for lua 3.2 and lua 4.0 that does this and also
> what require will do. It searches the current directory first, and
> then the environment variable LUA_SCRIPT_PATH. It would be nice if
> this functionality were part of the standard behavior of lua.

I would like to cast a dissenting vote here.

Lua's primary goal is to make a powerful language available to those who
wish to embed one in their products.  With every platform-specific feature
you add, you bloat the language for no gain.  (Yes, environment variables
and paths are platform-specific.  Hell, so are directories for that
matter.;-)

One of the reasons that I really like Lua is that it has provided me with a
powerful embeddable language that is both small and fast.  I'd rather see
it kept that way.  Each idea I've seen mentioned here (for the most part)
has sounded wonderful, but hardly universally applicable.  The more
domain-specific material we add, the less useful Lua becomes overall.

Perhaps this is fruitful work for add-on libraries instead of language
changes?

- --
Michael T. Richter
"Be seeing you."

-----BEGIN PGP SIGNATURE-----
Version: PGP Personal Privacy 6.5.3

iQA/AwUBOtNWHrTM3QkE7U/oEQL/bQCgmUCxXYJ1GUgdBXvLnkCO4JzOfJ0AoJJA
ahESJO8TR+Pf1qKa5RWevODw
=rH26
-----END PGP SIGNATURE-----



Reply | Threaded
Open this post in threaded view
|

Re: Supports Lua Includefiles?

Luiz Henrique de Figueiredo
In reply to this post by Luiz Henrique de Figueiredo
>Perhaps this is fruitful work for add-on libraries instead of language
>changes?

"require" will be part of the base library and not part of the language.
Plus it will use a global variable instead of an environment variable.
But, yes, directories (and dir separators) are a problem...
--lhf

Reply | Threaded
Open this post in threaded view
|

Re: Supports Lua Includefiles?

Patrick E. Hughes
In reply to this post by Michael T. Richter-2
<delurk>

>I would like to cast a dissenting vote here.

I second that motion.

>wish to embed one in their products.  With every platform-specific feature
>you add, you bloat the language for no gain.  (Yes, environment variables
>and paths are platform-specific.  Hell, so are directories for that
>matter.;-)

Without breaking too many NDAs all at once, something like the XBox has a
very anemic file system that wouldn't support any directory or naming
specific features at all.  And the cartridge based systems like N64 don't
have one at all except on their RAM storage cards.

>Perhaps this is fruitful work for add-on libraries instead of language
>changes?

Keeping the language separate from the surrounding utilities is wise, IMHO.

</delurk>


Reply | Threaded
Open this post in threaded view
|

Re: Supports Lua Includefiles?

Roberto Ierusalimschy
> (Yes, environment variables and paths are platform-specific.
> Hell, so are directories for that matter.;-)

That is all true (well, `getenv' is ANSI). But `require' should compile and 
run on any platform, as we do not use explicitly directories or paths in 
the implementation. We get a `getenv' or a global variable named LUA_PATH, 
break it along ';', concatenate each piece with the given file name, and 
try to run each result. All these operations (and their overall effect) 
have a clear and well-defined behaviour in any ANSI platform. For instance, 
if LUA_PATH="a;b;c" and you run "require d.lua", Lua will try to run the 
files 'ad.lua', 'bd.lua', and 'cd.lua'. The concepts of paths and 
directories are only a "standard" way to use the function
(for instance, saying LUA_PATH="/usr/local/lua/;./").

>Perhaps this is fruitful work for add-on libraries instead of language
>changes?

As lhf pointed out, require will be in a standard library, not in the 
kernel. The point of require being in the standard library is that it will 
give us more power to build other add-on libraries.  (If `require' was
implemented as a separate library, we would need it to load it ;-) Anyway,
as usual, it is too easy to remove it from lbaselib if you really need
a small implementation.

-- Roberto

Reply | Threaded
Open this post in threaded view
|

Re: Supports Lua Includefiles?

Christian Vogler-2
In reply to this post by Michael T. Richter-2
On Tue, Apr 10, 2001 at 02:51:12PM -0400, Michael T. Richter wrote:
> > what require will do. It searches the current directory first, and
> > then the environment variable LUA_SCRIPT_PATH. It would be nice if
> > this functionality were part of the standard behavior of lua.


> Lua's primary goal is to make a powerful language available to those who
> wish to embed one in their products.  With every platform-specific feature
> you add, you bloat the language for no gain.  (Yes, environment variables
> and paths are platform-specific.  Hell, so are directories for that
> matter.;-)

The problem, as I see it, is that without such a feature it is
downright *impossible* to take advantage of reusable libraries in
lua. If you have no portable method of loading useful add-on features,
then how are we ever going to extend the functionality of the base
libraries for those people who need it? The libraries that come with
lua are very spartan (no offense intended to the authors; I understand
that there are tradeoffs involved).

For our application we needed a much more powerful set of library
functions than what the standard lua installation provides. We had to
write this one ourselves, which was a fairly time-consuming
process. Wouldn't it be nice if we could make them available in some
kind of repository, similar to perl's CPAN archive, so that other
people who need their functionality need not write *their* own
versions from scratch again? But that won't help if lua does not
provide the necessary functionality to load these libraries in a
platform-independent manner.

That's a huge gain for a very minor amount of additional code (IMHO).

Besides, I don't see a problem if this "require" is provided as part
of the baselib, instead of the core language.

- Christian

Reply | Threaded
Open this post in threaded view
|

Re: Supports Lua Includefiles?

Michael T. Richter-2
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

> Besides, I don't see a problem if this "require" is provided as part
> of the baselib, instead of the core language.

I agree with this.  My concern was that it was going to be built into the
language proper, not as part of the library.  That concern is now assuaged.

- --
Michael T. Richter
"Be seeing you."

-----BEGIN PGP SIGNATURE-----
Version: PGP Personal Privacy 6.5.3

iQA/AwUBOtPSfLTM3QkE7U/oEQKH4gCgzRd+O8EsAIg9mEU9O6XxtkfZKT8AoN20
ybN7El33smGECsFJaWNfVHBT
=Wmqy
-----END PGP SIGNATURE-----