[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: modifying lua for table indexing with fixed point variables
- From: "Jerome Vuarand" <jerome.vuarand@...>
- Date: Mon, 28 Apr 2008 11:24:47 -0400
Gregory Lamoureux wrote:
> I've modified Lua to work using only fixed point 32 bit integers.
> ie, any number entered in a script or interpreter is automatically
> intercepted and converted to fixed point values (1e10 -> 655360,
> 0x0002->131072, etc..). Most of the changes were made to luaconf.h,
> but there were two other issues I had to fix:
>
> 1. the default increment value for "for" loops was originally "1". I
> changed it to 1<<16 = 65536. - no problems
>
> 2. Table indexing gets messed up if the user types:
>
> t = {"one","two","three","four","five"}
> print(t[2])
>
> because internally this will be read as "print(t[131072])". I
> have half fixed this issue. I modified primaryexp() function within
> lparser.c as below. If the expression to be dereferenced is a number
> (ex: print(t[2+1])), key.k == VKNUM and I can directly change shift
> the number back from fixed point to integer. Problem: if the
> expression to be dereferenced is a variable (ex: a = 2; print(t[a]))
> then key.k == VNONRELOC and I can't find the result register the
> number is stored in.
Shouldn't you instead modify the table construction code so that
{"one","two","three","four","five"} use indices 1<<16, 2<<16, 3<<16,
4<<16 and 5<<16 ? That would solve any indexing issue. You would however
have to modify the array-part optimisation of Lua tables (specifically
the code that determine what keys are valid array indices), but I think
that overall it's more consistent.