lua-users home
lua-l archive

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


Hi all,

I'm new to Lua and presently trying out some things. I'm especially interested in indirect access to variables and functions. No problems with variables, but the following puzzles me:

--------------------------------------------------
function afunc(x)
    print("afunc(" .. tostring(x) .. ") called")
    return x
end

function indirect(str)
    local result = loadstring(str)()
    print(tostring(result))
end

x = 42
indirect("afunc(x)")
--------------------------------------------------

The output is:

afunc(42) called
nil

Can anybody explain why the output is nil instead of 42?

Thanks,
Bernd
--
Bernd Eggink
http://sudrala.de