lua-users home
lua-l archive

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

Roberto Ierusalimschy wrote:
What version of Lua are you using?
Buggers always forgets to mention this, it's vanilla 5.0.2 (except some minor tweaks)

Can you send a complete piece that shows the bug?
Ok, this is a bit awkard example, but it gives the same kind of error I've experinced
in a more sane situation (but with alot more code surrounding it):

> do
        local test = {}
        test.__index = test

        function test:foo()
                return self[1]

        function test:func( idx )
		-- this if statement will cause the error, on purpose now..
                if then return false end
                return self:foo() + idx

        function new_test()
                return setmetatable( { 1, 2, 3, 4, 5 }, test )
> t=new_test()
> =t:func(3)
R2RMon: stdin:10: attempt to index local `self' (a number value)
stack traceback:
        stdin:10: in function <stdin:9>
        (tail call): ?
        [C]: in function `yield'
        const/hal:38: in function `counts'
        const/event:106: in function <const/event:97>

and running my own little lua debugger to see the locals at line 10 above:
> do
>> debug_bp("stdin", 10)
>> t:func(3)
>> end
run until breakpoint
stdin:func():10: locals
1       self    table: 15c7a4
2       self    3
stdin:func():10: step
R2RMon: stdin:10: attempt to index local `self' (a number value)

Where the debugger runs this to list the locals:
function opts.l(ar, level)
	local n, v, i
	i = 1
	print "locals"
		n, v = debug.getlocal(level, i)
		if n then print( i, n, v ) end
		i = i + 1
	until not n
	return debug_opt(ar, level + 1)

Hope this helps, I'll share more if needed to see what's going on..

I tried the same example on linux, which gave the expected result:
> =t:func(3)
stdin:10: attempt to index local `idx' (a number value)
stack traceback:
        stdin:10: in function <stdin:9>
        (tail call): ?
        [C]: ?

Please tell us where are those places so we can correct them.

sorry for not doing a diff patch thingy, but I already had modifications
done when first importing the sources to our repos (silly me), and don't
wont to bother figuring out how to do diff right now else where..

So here goes:

lines 44, 46: changed type from int to long, since the comment says it
might hold values that won't fit in 16 bits.
-- Not sure if anything was broken before this change, that got fixed by it
-- only did this with the previous comment in mind

integer const larger than 16 bits makes my compiler complain (only warning,
so it's no big deal) but it makes me wonder if the calculations may get wrong
depeding on input vs. output since it uses int's, and I haven't traced any
wrong behaviour to this so I haven't bothered change the signature to use long
instead since it affects the code in too many places.
-- I have removed the if statement, only using the latter else block from line 67 on.

Oh, I remebered it as being more, but the rest is only mods regarding to functionality
not supported/present on our hardware/os.

On a side note though, I'm missing an integer version of mod in the math lib, since
the real version may give answers that should be == to an int number, but isn't due
to floating point representational issues (see other recent thread regarding this).
For reference: here's a cut-n-paste solution in lua:
function math.imod(v, m)
	return v - m * math.floor(v/m)

Thanks for the report.
No problem. Love to be of help.
The least I can do in return for all we get from using lua.