lua-users home
lua-l archive

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


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"}

    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.

Question: Can somebody please tell me how I can access the result register where the _expression_ is stored?  I think the register number is in "" at the line marked TODO below.  Thank you very much!

case '[': {  /* `[' exp1 `]' */
        expdesc key;
        luaK_exp2anyreg(fs, v);
        yindex(ls, &key);


        if(key.k == VKNUM)
            //if it's a number we need to shift it over
            key.u.nval = key.u.nval >> LUA_FIXED_POINT_SHIFT;
            luaK_indexed(fs, v, &key);
        else if(key.k == VRELOCABLE)
            //if it's a variable or _expression_ we need access it and convert from fixed point to integer
            luaK_indexed(fs, v, &key);

            //key.k == VNONRELOC now
            //check the result register at
            //TODO: how do I access this register?????


        luaK_indexed(fs, v, &key);