[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Cell valuese in Lua state
- From: "Aaron Brown" <aaron-lua@...>
- Date: Thu, 14 Apr 2005 11:04:35 -0400
Dušan Majkić wrote:
> When I write in cell something like "=A1*1.5-SUM(B5:F5)"
> and when that cell is recalculated, evrything after "="
> should go to lua_dostring().
> What is the best way to represent cell values (eg. A1, B5)
> in lua state?
Here's one way: Appropriately mung the string (e.g.,
concatenate the cell name on to the beginning), turn it into
a function with loadstring, then give that function an
environment that doesn't have any functions that you don't
want the user to have access to, but does have the values of
the other cells. These other values can either be stored
directly in the environment, or the environment can have a
metatable with __index and __newindex metamethods.
On a similar topic, I recently worked on a project where I
wanted the user to be able to type in either
and have a variable be set to 42. My hack for doing this
was to loadstring the string first with a prepended
"return " and then, if that didn't work, without one.
"PHP combines the orthogonality of sh with the elegance
of <font color=ad0000> Fatal error: Cannot redeclare
quuxitate() (previously declared in -:4) in - on line 6