Coder Social home page Coder Social logo

Lua中如何实现Yield break? about xlua HOT 9 CLOSED

tencent avatar tencent commented on June 13, 2024
Lua中如何实现Yield break?

from xlua.

Comments (9)

chexiongsheng avatar chexiongsheng commented on June 13, 2024

lua那直接return就可以相当于Yield break。
不用stopCoroutine,你不resume协程,然后引用也不指向它,自然它会被gc掉。

from xlua.

dongxue avatar dongxue commented on June 13, 2024

如果我想中断一个运行中的Coroutine(不通过内部return的方式),你的建议是什么呢?

from xlua.

chexiongsheng avatar chexiongsheng commented on June 13, 2024

在外部没有什么中断好说,lua是单线程的,当你在外部的时候,就代表这个协程不在运行,你不resume直接抛弃掉即可。

from xlua.

chexiongsheng avatar chexiongsheng commented on June 13, 2024

你是被Unity用genarator模拟的协程给误导了。Unity的模拟需要把一个genarator注册到协程调度里头,你在外部也要调用个Stop来反注册。

from xlua.

dongxue avatar dongxue commented on June 13, 2024

在06_Coroutine范例中我通过在coruntine_test.lua中使用CS.GameObject.Destroy(gameobject)来实现了

from xlua.

chexiongsheng avatar chexiongsheng commented on June 13, 2024

哦,我理解错了,你是要中断在和Unity协程配合时,怎么清理Unity协程的问题。。不好意思!

from xlua.

dongxue avatar dongxue commented on June 13, 2024

另外我想请教下,为了hotfix,我理论上是不是可以给所有自己的C#类打上HOTFIX_ENABLE,这样做有什么坏处么?

from xlua.

chexiongsheng avatar chexiongsheng commented on June 13, 2024

我在这里有分析overhead:https://www.zhihu.com/question/54344452,可以去看看

from xlua.

BeatMicrosoft avatar BeatMicrosoft commented on June 13, 2024

LuaException: xlua/util.lua:16: c# exception:Non-static method requires a target.,stack: at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x000fe] in /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:236
at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MethodBase.cs:115
at XLua.OverloadMethodWrap.Call (IntPtr L) [0x0021f] in C:\Users\Administrator.X9WRY5BD2TWFRD2\Desktop\mohe-unity-mahjong-client\Assets\ThirdParty\XLua\Src\MethodWarpsCache.cs:242
at XLua.MethodWrap.Call (IntPtr L) [0x00041] in C:\Users\Administrator.X9WRY5BD2TWFRD2\Desktop\mohe-unity-mahjong-client\Assets\ThirdParty\XLua\Src\MethodWarpsCache.cs:297
stack traceback:
[C]: in function 'assert'
xlua/util.lua:16: in function <xlua/util.lua:14>
XLua.LuaEnv.ThrowExceptionFromError (Int32 oldTop) (at Assets/ThirdParty/XLua/Src/LuaEnv.cs:430)
XLua.DelegateBridge.__Gen_Delegate_Imp0 () (at Assets/ThirdParty/XLua/Gen/DelegatesGensBridge.cs:34)
Coroutine_Runner+c__Iterator0.MoveNext () (at Assets/Scripts/Framework/Coroutine_Runner.cs:21)
UnityEngine.SetupCoroutine.InvokeMoveNext (IEnumerator enumerator, IntPtr returnValueAddress) (at C:/buildslave/unity/build/Runtime/Export/Coroutines.cs:17)

但是他报这个错啊,我啥都没管

`
local yield_return = (require 'cs_coroutine').yield_return
self.co = coroutine.create(function()
while true and not self.stop_coroutine do
for i,v in ipairs(self.all_item) do
if self.all_item[i].IsNull() then

						end
						self.all_item[i].anchoredPosition = Vector2(0, self.all_item[i].anchoredPosition.y + 1)
						if self.all_item[i].anchoredPosition.y >= 90 then
							self.all_item[i].anchoredPosition = Vector2(0,-(#self.all_item - 1) * (90 + 6))
						end
					end
					if not self.stop_coroutine then
						return
					end
					yield_return(CS.UnityEngine.WaitForSeconds(0.0001))
				end
			end)
			coroutine.resume(self.co)

`

from xlua.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.