lua-users home
lua-l archive

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



> -----Original Message-----
> From: owner-lua-l@tecgraf.puc-rio.br
> [mailto:owner-lua-l@tecgraf.puc-rio.br]On Behalf Of Steve Dekorte
> Sent: Tuesday, May 22, 2001 3:22 PM
> To: Multiple recipients of list
> Subject: Re: Making vars local by default
> In that case, would this do the job?
>
> function eval(s)
>    return dostring("local f = function () "..s.." end; return f()")
> end

AFAICT, that is no different from dostring( s ). But dostring(s) is only the
right behavior if s already contains an explicit return. Right now, I just
do a simple string search for the word "return" but that strikes me as too
kludgy.

After having given this some more thought, I have realized that part of the
issue is that "return" actually has two behaviors that are sandwitched into
one. This was probably a good idea in single-return-value languages like C,
but in lua I don't think it necessarily makes sense:

1) Push one or more values onto a "return stack"
2) exit the current thread of execution and return the stack to its caller

Now, why couldn't we split these two things up. Just have a side-effect of
running code in the eval() context that each value is pushed onto an
implicit return stack. Explicit returns still operate as usual. But if the
eval() terminates before returning, then the implicit return stack is
automatically returned as a result.

Anything wrong with that approach?

Eric