loadstring()在Lua中包含一个函数

时间:2020-05-20 03:32:41

标签: lua

说,我有这个备忘录行文本:

Memo.Lines.Text = 'print('Hello World')
local test = Memo.Lines.Text
loadstring(test) ()

--result: Hello World

现在,如果是这样的话:

Memo.Lines.Text = [[
function playTest()
 local a = 10
 local b = 20
 local c = a + b
 print('This is a test of a math calculation: ')
 print(a..' + '..b..' is '..c)
end
]]

local test = Memo.Lines.Text
loadstring(test) ()
playTest()

-- result: error attempt to call a nil value 'playTest'

如何从字符串/作为上面的备注行文本返回函数?

0 个答案:

没有答案