lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


For me, it is strange that dofile() only takes one argument, the path
to the script file.
It seems so natural that additional parameters would be passed as
arguments to the script.
In fact, during LuaDura implementation in 2006, I rewrote dofile in
the following way:

function dofile(filename, ...)
	arg = {[0] = filename, ...}
	return assert(loadfile(filename))(...)
end

I know this is not 100% correct, since the global 'arg' variable is
not restored after the call.
Anyway, it has proved to be very handy like this.
Looking in the mailing list archive, I found only one question on this
subject [1] that has been quickly answered without any explanation.
Is there a good reason not to support arguments in dofile ?

Patrick Rapin

[1] http://lua-users.org/lists/lua-l/2005-07/msg00206.html