Reputation: 5962
My question has multiple parts but firstly here is my sample lua code (test.lua):
local traceback = debug.traceback
local inspect = require('inspect')
local foo = "function nop(); print('this is war'); return true; end"
local f = loadstring(foo)
local result = f()
print(result)
local status, val= xpcall(function () return f() end,debug.traceback)
print('status .. ' .. tostring(status))
print(val)
So,
When I run local result = f()
. I still see the result
value as nil
When the function f
is executed. Why don't I see the print
o/p .
Upvotes: 3
Views: 285
Reputation: 80921
The chunk of code in foo
which you load into f
doesn't return any values.
It defines a function but that's it.
If you want to return the function from the chunk when it is run you need to add return nop
to the end of the string.
Upvotes: 4