lua-users home
lua-l archive

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


So here's the problem.  I have wrapped some C structures with
functions that can take arguments of various types.  A simple example
is with the matrix functions.  If I call a setcell function on a uchar
matrix with integer arguments, the cell will be set with the integer
data clamped to the range [0, 255].  If I call the same function with
float arguments, the range will be clampeed to [0, 1] with the values
in this range mapping to the uchar range [0, 255].  This is pretty
standard behavior and mirrors OpenGL color values in the float case.

Now let's say I call the getcell function on a uchar matrix.  If the
cell is yellow with a little bit of blue channel, one scenario is that
I get a table with values {255, 255, 255, 1} where the first value is
the alpha channel.  If I then use this same table to set another cell
in the matrix, the cell will end up white because a float value of 1
is actually 255 in uchar values.


But now that I think about it some more, the problem is more
fundamental than distinguishing between 255 and 255. and I think I'm
going to have to convert everything into the float range because 255.
is textual and when for example the getcell function returns a table
of values there is no notion of the '.' because it is not in the
script text.

So, I guess I don't have a problem with Lua but need to rethink how
the bindings are done.  Thanks for prodding me to think about this
some more.  I guess I just needed to sound off of someone.

best,
wes


On 1/1/07, Asko Kauppi <askok@dnainternet.net> wrote:

What exactly is your end goal on this, that is _why_ do you need to
separate them?

Token filtering won't help, since numbers have already been tokenized
prior to coming to the filter. So you'll get "<number>"+X or
"<string>"+Y or "for" and other tokens.

If you require different behaviour, you'll probably need to do a dbl
() function (s.a. dbl(255)) that would wrap the number into a
userdata. I'd hate to do such in my code!

But let's hear, what is your actual problem? :)

-asko


Wesley Smith kirjoitti 2.1.2007 kello 1.25:

> Hi,
> Is there a way to use token filtering in Lua to distinguish {255, 1,
> 1, 255} from {255., 1., 1., 255.} in C?  I'd like the former to
> resolve as int and the later to resolve as floats.
>
> thanks,
> wes