lua-users home
lua-l archive

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


On 10/18/11, marbux <marbux@gmail.com> wrote:
> On Mon, Oct 17, 2011 at 3:59 PM, joao lobato <btnfdp.lobato@gmail.com>
> wrote:
>> On 10/17/11, Josh Simmons <simmons.44@gmail.com> wrote:
>
>> Actually, what I don't understand is dofile; I always find it wierd
>> that it can't be passed arguments...
>
> Might you enlighten me with a use case that can't be worked around via
> dofile's ability to pass global variables?
>
> (Not trying to be sarcastic; I'm close to being a novice scripter and
> sincerely do not see a use case.)
>
>

My point was simply that dofile can be replaced by something like

function my_dofile(name,...)
  return assert(loadfile(name))(...)
end

and still end up with more functionality; in a way I was alluding that
we never had a dostring (it's pretty much the same idiom but with the
deprecated loadstring).

Globals tend to be dangerous, you have no guarantees regarding what
part of the script can end up mucking your state; shared memory is
always a source of endless problems.

Of course the point loses much of its weight for small scripts with a
single developer.