[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Confused about local function bug. RE: Lua 5.0 -> 5.0.1
- From: "Tai Meng" <tmeng@...>
- Date: Tue, 7 Oct 2003 15:08:18 -0700
I have just applied the Lua 5.0.1 patch in hopes of fixing a 'local function' bug that I've encountered. However, given:
======== test.lua ================
var = "shadowed"
var2 = "hi"
local foo; foo = function()
local var = "var"
local var2 = "hi"
print("")
end
print(foo)
======== test.lua ================
I attach a line hook, and display the local variables associated with the main chunk using lua_getlocal(). If line = 7, the line hook has been triggered *before* line 7. Here is the output:
============= LOCALS & UPVALUES =============
File name: ../../scripts/test.lua, Line: 7
local 1: foo, Value: nil
File name: ../../scripts/test.lua, Line: 9
local 1: foo, Value: 00815230
function: 00815230 -- from print(foo)
============= LOCALS & UPVALUES =============
So far so good. But, if I were to change the third line to "local function foo()", as below
======== test.lua ================
var = "shadowed"
var2 = "hi"
local function foo()
local var = "var"
local var2 = "hi"
print("")
end
print(foo)
======== test.lua ================
I get:
============= LOCALS & UPVALUES =============
File name: ../../scripts/test.lua, Line: 7
local 1: foo, Value: hi
File name: ../../scripts/test.lua, Line: 9
local 1: foo, Value: 00815308
function: 00815308 -- from print(foo)
============= LOCALS & UPVALUES =============
The 3rd lines of both test.lua files are equivalent according to section 2.5.8 of the Lua 5.0 manual. However, one behaved as expected, and the other, not. Before upgrading from Lua 5.0 to Lua 5.0.1, the same outputs were generated. So, I am confused. Could I have been doing something wrong in my code? Or does this seem like an issue with Lua?
Tai
-----Original Message-----
From: Luiz Henrique de Figueiredo [mailto:lhf@tecgraf.puc-rio.br]
Sent: Tuesday, October 07, 2003 7:44 AM
To: lua@bazar2.conectiva.com.br
Subject: Re: Lua 5.0 -> 5.0.1
Here is the list of changes.
--lhf
This is Lua 5.0.1, an update of Lua 5.0 that includes the following changes,
which fix all known bugs in Lua 5.0.
src/ldo.c
Attempt to resume running coroutine crashed Lua
src/lgc.c
C functions also may have stacks larger than current top
Userdata to be collected still counted into new GC threshold
src/lgc.h
Userdata to be collected still counted into new GC threshold
src/lparser.c
syntax `local function' did not increment stack size
src/lvm.c
`pc' address was invalidated when a coroutine was suspended
Count hook might be called without being set
src/lib/lbaselib.c
Buffer overflow for unusual %p representation
src/lib/liolib.c
`file:close' could not be called without a file
Buffer overflow for unusual %p representation
To use this update, simply open this tarball over the original Lua 5.0 source.