说,我有此备忘录行文本:
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'
如何从字符串/以上面的备注行文本形式返回函数?
糟糕,没关系,这是答案
loadstring(test) (PlayTest)
playTest()