[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: Working with Lua 5.1 'require' for fake/virtual/non-standard files
- From: "Daniel Collins" <daniel.collins@...>
- Date: Tue, 6 Jun 2006 10:16:32 +0930
I had a similar situation with my project, where the C standard library
file functions are not available. So I wrote my own file IO functions
that mapped to the C library file functions. Then I ensure that lua uses
my file functions.
For compressed or encrypted files (and even for "files" that are
actually binary data linked into the executable), it is not hard to
write a system that emulates the C library file API. This way lua
doesn't need to even notice the difference, at least for read only
files. Since my project is running on an embedded system, I have
disabled file writing from lua altogether. I can still write on some
platforms but only from the C side of things.
The end result is that my lua scripts can use require and dofile in
exactly the standard way, even though the actual file data may exist as
a compressed binary resource linked into the executable, or in a
compressed archive file, or as a normal file.
For linked binary data, and compressed archive files, the C code has to
mount this file with the file system before it can be accessed, but this
is done outside of lua.
- DC
-----Original Message-----
From: lua-bounces@bazar2.conectiva.com.br
[mailto:lua-bounces@bazar2.conectiva.com.br] On Behalf Of E. Wing
Sent: Tuesday, 6 June 2006 6:23 AM
To: lua@bazar2.conectiva.com.br
Subject: Working with Lua 5.1 'require' for fake/virtual/non-standard
files
I've been using 'require' as basically a #include (actually more like
#import) for Lua scripts. However, I've been using one of those zip
packaging systems like zzipllib or PhysFS so all my scripts are
contained within a single large zip file. This means I cannot use
standard ANSI C file methods to access these files. In Lua 5.0, I simply
cut-and-paste the function "luaB_require" function located in lbaselib.c
and made a few code substitutions to go through my own file loaders
(which ultimately use loadbuffer) instead of lua_loadfile. I was
fortunate that this function used all public APIs so I could continue to
use stock Lua and just make my scripts use my special version of require
(e.g. mystuff.require).
I've started migrating to Lua 5.1, but the old 'luaB_require' code I
copied no longer compiles. I noticed that 'require' code base is
considerably more complicated than before. I've been sniffing around
loadlib.c, but I'm getting the impression that it uses more than just
public APIs. I would like to continue using stock Lua.
So I was wondering if somebody can explain to me how I can work with the
new 5.1 system to load my zipped/archived scripts, in a way that doesn't
require me to modify stock Lua or modify all my scripts. (I prefer my
changes to be in the C part of my program).
Thanks,
Eric