lua-users home
lua-l archive

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


> This is only tangentially related to this discussion, but I feel it may
> affect the Lua-as-language vs Lua-as-configfile line up.
> 
> I am curious if it would be worthwhile to implement a perl-style eval() for
> executing lua code. Lua's dostring() is very close, but eval() has the added
> advantage of automatically returning the last statement executed. So for
> instance eval( "10" ) is equivalent to dostring( "return 10" )
> 
> I have found this behavior to be especially useful in both scripting
> language and config file contexts. In fact, I think we could probably expand
> upon it, perhaps deciding on some additional behaviors that perl does not
> have. In particular, I think it might be handy for eval() to return a table
> of all of the expressions evaluated during the call. So the following two
> would be equivalent
> 
> foo = eval( "function foo() ... end { a = 1, b = 2 }" )
> 
> foo = dostring( "return { function foo() ... end, { ... } }" )
> 
> Any thoughts?
> 
> Eric

I can think of a very specific place such an eval() function would be useful 
for my NebLUA project - in the Nebula console one currently has to have an 
explicit 'return' before any calculation one wants to see the results of. The 
TCL version is nice enough to print it to the console... I didn't see any way 
to make the lua version do the same, other than hacking the lua code itself. 
Anyhoo, that's just my $.02 USD.

--James Hearn
http://logichole.codevault.org/