【发布时间】:2014-02-27 14:01:12
【问题描述】:
我正在为系统构建一个插件。系统偶尔会调用我插件的update() 方法。
在我的插件的update() 方法中,我正在修改系统状态,但是在系统有机会这样做之前系统状态不会更新(这发生在update 方法的调用之间)。
所以每当我执行系统更新方法时,我都必须从update() 一路返回,让它返回,然后重新进入,然后我必须尝试回到哪里我曾是。我一直在考虑一种更聪明的方法来做到这一点,即通过保存调用框架等。然后在返回时加载该调用框架。
但我并没有开始自己实现这一点,而是在考虑是否已经有办法做到这一点。我正在编写的插件是在 Lua 中,通过 C# 的 NLua 库。
如果需要,我可以访问 C# 环境!
我有一个想法,我需要像延续这样的东西?
我想拥有的示例;
update() --> ... --> helper_function() --> system_state_modifier()
// System state modifier changes system state, saves the current stack/registers,
// whatever else is needed, and returns directly to update()'s caller
// On the next call to update, the previous stack/registers and such
// is restored, and continued.
【问题讨论】:
-
我想你想使用协程。
标签: c# lua continuations nlua