[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Is "scripting" truly Lua's future?
- From: mr <vbqadc@...>
- Date: Tue, 16 Sep 2008 02:31:28 +0000 (GMT)
> >> All my Lua files tend to start with the same
> boilerplate containing
> > ...
> >> ...etc. It would be really nice to be able to
> common this somehow.
> >
> > You can write your own lua_Reader function that send
> this before sending
> > anything else.
>
> Yes, but the line numbers in the debug information will
> still be wrong
> --- because the compiler's seen 15 or so lines before
> the main text
> starts, all the numbers will be 15 or so out. I've had
> to deal this
> before in other languages and it's significantly more
> of a pain that it
> seems.
here is a quick prototype for including other files:
local scripts = {
"script.lua",
}
local replacer = function( header )
local file = io.open( header )
local chunk = file:read "*a"
file:close( )
return string.gsub( chunk, "\n", " " ) .. " " -- replace newlines
end
local execute = function( chunk, script )
script = script .. ".tmp"
local file = io.open( script, "w+" ) -- tmp output
file:write( chunk )
file:close( )
dofile( script )
end
for i, script in ipairs( scripts ) do
local file = io.open( script )
local chunk = file:read "*a"
file:close( )
execute( string.gsub( chunk, "local include = \"(.-)\"", replacer ), script )
end
when you want to include a header, use
local include = "header1.lua"
local include = "header2.lua"
at top of your script.
cheers, marc
__________________________________________________
Do You Yahoo!?
Sie sind Spam leid? Yahoo! Mail verfügt über einen herausragenden Schutz gegen Massenmails.
http://mail.yahoo.com