[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Attempt to perform arithmetic on a string value
- From: Ben Sunshine-Hill <bsunshin@...>
- Date: Sun, 28 Mar 2004 22:43:32 -0800
The only way to do that automatically would be to modify the Lua source code.
At a quick glance, it looks like the best place to make lua accept the empty
string as 0 would be to modify lobject.c, changing luaO_str2d as follows
(under 5.0): change
if (endptr == s) return 0; /* no conversion */
to
if (endptr == s && *endptr) return 0; /* no conversion */
Code barely tested. Caveat emptor.
Ben
On Sunday 28 March 2004 10:09 pm, Stoil Todorov wrote:
> Thank You, but I want when there are arithmetic
> operation with string and number, and if the string is
> empty, the result to be 0/zero/ or ""/empty string/.
>
> --- RLake@oxfam.org.pe wrote:
> > > Could someone tell me how to avoid the error,
> >
> > wchich
> >
> > > LUA sends when it performs arithmetic operation
> >
> > with
> >
> > > empty string value.
> >
> > Consider changing the logic of your program so that
> > the
> > initial value of A2.value is 0 instead of "" ?
> >
> > Otherwise, try this:
> >
> > function optnumber(s)
> > return tonumber(s) or (s == "" and 0) or
> > error("expected number, got
> > "..type(s))
> > end
> >
> > or some other variation on the theme.
>
> __________________________________
> Do you Yahoo!?
> Yahoo! Finance Tax Center - File online. File on time.
> http://taxes.yahoo.com/filing.html
--
Ben Sunshine-Hill
Student and Programmer
Your lucky words for today: campfire, bridegroom, and scornfully.