debug.getupvalue
Örnek
Bazı yerel fonksiyonların upvalue'larını yazdırır.
local foo = 5
local bar = "hello"
local test = { "table", true, "variable" }
local function DoSomethingWithFoo()
-- Bu kod çalıştırılmayacak ancak fonksiyonun
-- bir upvalue olarak sayılabilmesi için
-- değişkene referans vermesi gerekir
foo = foo + 1
end
local function DoSomethingWithFooAndBar()
foo = foo / 2
bar = bar .. " world"
end
local function DoSomethingWithBarAndTest()
test[1] = bar .. "reader!"
end
-- level = yerel değişkenlerin alınacağı yığın seviyesi
-- değişken adını temsil eden string anahtarlı bir tablo döndürür
local function GetUpvalues( func )
local info = debug.getinfo( func, "uS" )
local variables = {}
-- Upvalue'lar C fonksiyonlarından alınamaz
if ( info != nil && info.what == "Lua" ) then
local upvalues = info.nups
for i = 1, upvalues do
local key, value = debug.getupvalue( func, i )
variables[ key ] = value
end
end
return variables
end
print( "DoSomethingWithFoo:" )
PrintTable( GetUpvalues( DoSomethingWithFoo ) )
print( "\nDoSomethingWithFooAndBar:" )
PrintTable( GetUpvalues( DoSomethingWithFooAndBar ) )
print( "\nDoSomethingWithBarAndTest:" )
PrintTable( GetUpvalues( DoSomethingWithBarAndTest ) )
Çıktı:
DoSomethingWithFoo:
foo = 5
DoSomethingWithFooAndBar:
bar = hello
foo = 5
DoSomethingWithBarAndTest:
bar = hello
test:
1 = table
2 = true
3 = variable
Tüm sunucular · GmodTR Launcher · Rehber · GMod Wiki · GmodTR nedir? · Sunucu ekle · Discord