[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Extending dofile() to pass arguments
- From: Daurnimator <quae@...>
- Date: Wed, 4 Jan 2012 19:01:42 +1100
On 4 January 2012 17:46, HyperHacker
<hyperhacker@gmail.com> wrote:
Just wondering if there's a compelling reason not to do this. Right
now if you want to load a script and pass some arguments to it, you
have to do:
loadfile('myscript.lua')(a, b, c)
and if you want to handle errors, it gets uglier:
assert(loadfile('myscript.lua'))(a, b, c)
It seems like a simple, useful change would be to allow dofile() to
pass arguments:
dofile('myscript.lua', a, b, c)
Thoughts? Of course this can be done pretty easily within Lua itself,
but I'm not terribly fond of replacing built-in functions like that.
Is there a reason this couldn't be done in a future version of Lua?
Will bad things happen to me if I wrap dofile() in my scripts to do
this? To me it seems to be in the spirit of Lua: a tiny change that
makes our code simpler. But I wonder if there's some detail I've
missed that would make it a bad idea...
--
Sent from my toaster.
I'm all for it;
The one place I can think of that something will break is if someone calls it dofile around a gsub and the script doesn't like it.
dofile(mystr:gsub("x","y"))
On the other hand this is such a simple and non-consequential change that if this thread goes past around 5 posts I'll have to execute you all for bikeshedding.