作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的问题有多个部分,但首先这是我的示例 lua 代码 (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)
所以,
当我运行 local result = f()
时。我仍然看到 result
值为 nil
当函数 f
被执行时。为什么我看不到 print
o/p。
最佳答案
您加载到 f
中的 foo
中的代码块不会返回任何值。
它定义了一个函数,仅此而已。
如果你想在运行时从 block 中返回函数,你需要将 return nop
添加到字符串的末尾。
关于lua - 为什么我在我的 lua 函数中看不到打印,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32272377/
我是一名优秀的程序员,十分优秀!