lua 动态停止或操纵函数

我想要做的是在lua中动态停止一个函数。我尝试过的代码:

local SaveReal = Thread
local stopped  = false

--[[
Thread function runs the lua function
that it includes in a separate thread.
It was created before here
and is trying to be manipulated here.
]]--
Thread = function(func)
  SaveReal(function()
    while(not stopped) do
      func()
    end
  end)
end

Thread(function()
  while(true) do
    print("Thread working")
  end
end)

如果我能把函数的内容读成一个字符串,我就可以用load将其加载到我的操纵函数中,只有当我的标志为false时代码才会不起作用。

点赞
用户7746452
用户7746452

Lua有一些称为协同程序的东西,用于提供多任务处理(不是多线程处理)。

2020-12-07 23:32:22