luau/tests/conformance/ndebug_upvalues.lua
Harold Cindy 729bc44729
Fix lua_*upvalue() when upvalue names aren't in debug info (#787)
`lua_getupvalue()` and `lua_setupvalue()` don't behave as expected when
working with Lua closure whose `Proto` has no debug info. The code
currently uses `sizeupvalues` to do bounds checking of upvalue indices,
but that's the size of the upvalue _names_ array. It will always be `0`
if the `Proto` doesn't have debug info.

This uses `nups` instead, and just returns `""` as the upvalue name if
we don't have one, same as for C closures.

Co-authored-by: Harold Cindy <HaroldCindy@users.noreply.github.com>
2023-01-18 06:00:13 -08:00

14 lines
396 B
Lua

-- This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
-- This tests that the lua_*upval() APIs work correctly even with debug info disabled
local foo = 5
function clo_test()
-- so `foo` gets captured as an upval
print(foo)
-- yield so we can look at clo_test's upvalues
coroutine.yield()
end
clo_test()
return 'OK'