找回密码
 立即注册
查看: 288|回复: 0

测试 tolua 例子 TestErrorStack

[复制链接]
发表于 2021-8-11 20:03 | 显示全部楼层 |阅读模式
测试 tolua 例子 TestErrorStack

(金庆的专栏 2020.9)
Error1

    点击 “Error1” 按钮c# showStack.PCall()lua ShowStack()c# Test1()c# try { show.PCall() }lua Show() error(‘this is error’)
  1. LuaException: TestErrorStack:2: this is error
  2. stack traceback:
  3.         [C]: in function 'error'
  4.         TestErrorStack:2: in function <TestErrorStack:1>
  5.         [C]: in function 'Test1'
  6.         TestErrorStack:6: in function <TestErrorStack:5>
  7. LuaInterface.LuaState:PCall(Int32, Int32) (at Assets/ToLua/Core/LuaState.cs:758)
  8. LuaInterface.LuaFunction:PCall() (at Assets/ToLua/Core/LuaFunction.cs:96)
  9. TestLuaStack:Test1(IntPtr) (at Assets/ToLua/Examples/TestErrorStack/TestLuaStack.cs:27)
  10. LuaInterface.LuaDLL:lua_pcall(IntPtr, Int32, Int32, Int32)
  11. LuaInterface.LuaState:PCall(Int32, Int32) (at Assets/ToLua/Core/LuaState.cs:755)
  12. LuaInterface.LuaFunction:PCall() (at Assets/ToLua/Core/LuaFunction.cs:96)
  13. TestLuaStack:OnGUI() (at Assets/ToLua/Examples/TestErrorStack/TestLuaStack.cs:375)
复制代码
lua Show() 中抛 error, 在 C# 中 try-catch 得到,
通过 toluaL_exception() 返回 Lua 调用者 ShowStack(),
ShowStack() 中止执行,传递异常到 c# 调用者 OnGUI(),
OnGUI()中断执行,打印错误信息。
Instantiate Error

    “Instantiate Error”c# GetFunction(“Instantiate”).PCall()lua Instantiate()c# UnityEngine.Object.Instantiate(obj)c# TestInstantiate.Awake()c# try { GetFunction(“Show”).PCall() }lua Show()c# state.ThrowLuaException(e)
  1. LuaException: TestErrorStack:2: this is error
  2. stack traceback:
  3.         [C]: in function 'error'
  4.         TestErrorStack:2: in function <TestErrorStack:1>
  5.         [C]: in function 'Instantiate'
  6.         TestErrorStack:12: in function <TestErrorStack:11>
  7. LuaInterface.LuaState:PCall(Int32, Int32) (at Assets/ToLua/Core/LuaState.cs:758)
  8. LuaInterface.LuaFunction:PCall() (at Assets/ToLua/Core/LuaFunction.cs:96)
  9. TestInstantiate:Awake() (at Assets/ToLua/Examples/TestErrorStack/TestInstantiate.cs:15)
  10. UnityEngine.Object:Instantiate(Object)
  11. UnityEngine_ObjectWrap:Instantiate(IntPtr) (at Assets/ToLua/BaseType/UnityEngine_ObjectWrap.cs:203)
  12. LuaInterface.LuaDLL:lua_pcall(IntPtr, Int32, Int32, Int32)
  13. LuaInterface.LuaState:PCall(Int32, Int32) (at Assets/ToLua/Core/LuaState.cs:755)
  14. LuaInterface.LuaFunction:PCall() (at Assets/ToLua/Core/LuaFunction.cs:96)
  15. TestLuaStack:OnGUI() (at Assets/ToLua/Examples/TestErrorStack/TestLuaStack.cs:391)
复制代码
在 lua 中实例化对象,Awake() 中向lua抛异常:state.ThrowLuaException(e)。
中止了 lua 调用和 OnGUI(), 但是新对象的 Start() 成功调用了。
因为 Awake() 中 catch 了异常,按执行成功处理。
如果 Awake() 中不 catch, Awake() 执行异常,也不会有 Start() 调用,但是lua Instantiate() 执行会成功,打印出对象名。
Check Error

    “Check Error”c# GetFunction(“TestRay”).PCall()lua TestRay() return Vector3.zeroc# CheckRay(); //返回值出错
  1. LuaException: bad argument #2 (Ray expected, got Vector3)
  2. LuaInterface.LuaDLL:luaL_argerror(IntPtr, Int32, String) (at Assets/ToLua/Core/LuaDLL.cs:692)
  3. LuaInterface.LuaDLL:luaL_typerror(IntPtr, Int32, String, String) (at Assets/ToLua/Core/LuaDLL.cs:706)
  4. LuaInterface.LuaStatePtr:LuaTypeError(Int32, String, String) (at Assets/ToLua/Core/LuaStatePtr.cs:534)
  5. LuaInterface.LuaState:CheckRay(Int32) (at Assets/ToLua/Core/LuaState.cs:1505)
  6. LuaInterface.LuaFunction:CheckRay() (at Assets/ToLua/Core/LuaFunction.cs:781)
  7. TestLuaStack:OnGUI() (at Assets/ToLua/Examples/TestErrorStack/TestLuaStack.cs:403)
复制代码
Push Error

    “Push Error”c# func.Push(Instance);
  1. 14:04:31.371-157: Type TestLuaStack not wrap to lua, push as UnityEngine.MonoBehaviour, the warning is only raised once
  2. UnityEngine.Debug:LogWarning(Object)
  3. LuaInterface.Debugger:LogWarning(String)
  4. LuaInterface.Debugger:LogWarning(String, Object, Object)
  5. LuaInterface.LuaState:GetMissMetaReference(Type) (at Assets/ToLua/Core/LuaState.cs:1917)
  6. LuaInterface.LuaStatic:GetMissMetaReference(IntPtr, Type) (at Assets/ToLua/Core/LuaStatic.cs:39)
  7. LuaInterface.ToLua:LoadPreType(IntPtr, Type) (at Assets/ToLua/Core/ToLua.cs:2608)
  8. LuaInterface.ToLua:PushUserObject(IntPtr, Object) (at Assets/ToLua/Core/ToLua.cs:2622)
  9. LuaInterface.ToLua:Push(IntPtr, Object) (at Assets/ToLua/Core/ToLua.cs:2636)
  10. LuaInterface.LuaState:Push(Object) (at Assets/ToLua/Core/LuaState.cs:1378)
  11. LuaInterface.LuaFunction:Push(Object) (at Assets/ToLua/Core/LuaFunction.cs:465)
  12. TestLuaStack:OnGUI() (at Assets/ToLua/Examples/TestErrorStack/TestLuaStack.cs:412)
复制代码
LuaPushError

    “LuaPushError”c# GetFunction(“PushLuaError”).PCall()lua PushLuaError()lua TestStack.PushLuaError()c# PushLuaError()c# try { testRay.Push(Instance); }
仅是警告,没有异常
Check Error

    “Check Error”c# GetFunction(“Test5”).PCall()lua Test5()lua TestStack.Test5()c# Test5()c# GetFunction(“Test4”).PCall()lua TestStack.Test4()c# Test4()c# try { show.PCall() }
  1. LuaException: TestErrorStack:2: this is error
  2. stack traceback:
  3.         [C]: in function 'error'
  4.         TestErrorStack:2: in function <TestErrorStack:1>
  5.         [C]: in function 'Test4'
  6.         TestErrorStack:30: in function <TestErrorStack:29>
  7.         [C]: in function 'Test5'
  8.         TestErrorStack:34: in function <TestErrorStack:33>
  9. LuaInterface.LuaState:PCall(Int32, Int32) (at Assets/ToLua/Core/LuaState.cs:758)
  10. LuaInterface.LuaFunction:PCall() (at Assets/ToLua/Core/LuaFunction.cs:96)
  11. TestLuaStack:Test4(IntPtr) (at Assets/ToLua/Examples/TestErrorStack/TestLuaStack.cs:85)
  12. LuaInterface.LuaDLL:lua_pcall(IntPtr, Int32, Int32, Int32)
  13. LuaInterface.LuaState:PCall(Int32, Int32) (at Assets/ToLua/Core/LuaState.cs:755)
  14. LuaInterface.LuaFunction:PCall() (at Assets/ToLua/Core/LuaFunction.cs:96)
  15. TestLuaStack:Test5(IntPtr) (at Assets/ToLua/Examples/TestErrorStack/TestLuaStack.cs:102)
  16. LuaInterface.LuaDLL:lua_pcall(IntPtr, Int32, Int32, Int32)
  17. LuaInterface.LuaState:PCall(Int32, Int32) (at Assets/ToLua/Core/LuaState.cs:755)
  18. LuaInterface.LuaFunction:PCall() (at Assets/ToLua/Core/LuaFunction.cs:96)
  19. TestLuaStack:OnGUI() (at Assets/ToLua/Examples/TestErrorStack/TestLuaStack.cs:434)
复制代码
Test Resume

    “Test Resume”c# GetFunction(“Test6”).PCall()lua Test6()lua 协程中调用 TestStack.Test6(go)c# toluaL_exception()
lua coroutine resume() 返回 false, 不会有错误。
out of bound

    “out of bound”c# GetFunction(“TestOutOfBound”).PCall()c# TestOutOfBound()c# toluaL_exception(L, e)
  1. LuaException: Transform child out of bounds
  2. stack traceback:
  3.         [C]: at 0x613c2af0
  4. TestLuaStack:TestOutOfBound(IntPtr) (at Assets/ToLua/Examples/TestErrorStack/TestLuaStack.cs:136)
  5. LuaInterface.LuaDLL:lua_pcall(IntPtr, Int32, Int32, Int32)
  6. LuaInterface.LuaState:PCall(Int32, Int32) (at Assets/ToLua/Core/LuaState.cs:755)
  7. LuaInterface.LuaFunction:PCall() (at Assets/ToLua/Core/LuaFunction.cs:96)
  8. TestLuaStack:OnGUI() (at Assets/ToLua/Examples/TestErrorStack/TestLuaStack.cs:454)
复制代码
TestArgError

    “TestArgError”c# GetFunction(“Test8”).PCall()lua Test8()lua TestArgError()c# TestArgError()c# toluaL_exception(L, e)
  1. LuaException: TestErrorStack:69: bad argument #1 to 'TestArgError' (number expected, got string)
  2. stack traceback:
  3.         [C]: in function 'TestArgError'
  4.         TestErrorStack:69: in function <TestErrorStack:68>
  5. LuaInterface.LuaDLL:luaL_argerror(IntPtr, Int32, String) (at Assets/ToLua/Core/LuaDLL.cs:692)
  6. LuaInterface.LuaDLL:luaL_typerror(IntPtr, Int32, String, String) (at Assets/ToLua/Core/LuaDLL.cs:706)
  7. TestLuaStack:TestArgError(IntPtr) (at Assets/ToLua/Examples/TestErrorStack/TestLuaStack.cs:151)
  8. LuaInterface.LuaDLL:lua_pcall(IntPtr, Int32, Int32, Int32)
  9. LuaInterface.LuaState:PCall(Int32, Int32) (at Assets/ToLua/Core/LuaState.cs:755)
  10. LuaInterface.LuaFunction:PCall() (at Assets/ToLua/Core/LuaFunction.cs:96)
  11. TestLuaStack:OnGUI() (at Assets/ToLua/Examples/TestErrorStack/TestLuaStack.cs:463)
复制代码
TestFuncDispose

    “TestFuncDispose”c# func.Dispose();c# func.PCall();
  1. LuaException: LuaFunction has been disposed
  2. LuaInterface.LuaFunction:BeginPCall() (at Assets/ToLua/Core/LuaFunction.cs:73)
  3. TestLuaStack:OnGUI() (at Assets/ToLua/Examples/TestErrorStack/TestLuaStack.cs:473)
复制代码
SendMessage

    “SendMessage”c# gameObject.SendMessage(“OnSendMsg”);c# OnSendMsg()c# try { GetFunction(“TestStack.Test6”).PCall() }c# Test6()c# toluaL_exception(L, e);
  1. LuaException: this a lua exception
  2. stack traceback:
  3.         [C]: at 0x613c2af0
  4.         [C]: in function 'TestArgError'
  5.         TestErrorStack:69: in function <TestErrorStack:68>
  6. TestLuaStack:Test6(IntPtr) (at Assets/ToLua/Examples/TestErrorStack/TestLuaStack.cs:122)
  7. LuaInterface.LuaDLL:lua_pcall(IntPtr, Int32, Int32, Int32)
  8. LuaInterface.LuaState:PCall(Int32, Int32) (at Assets/ToLua/Core/LuaState.cs:755)
  9. LuaInterface.LuaFunction:PCall() (at Assets/ToLua/Core/LuaFunction.cs:96)
  10. TestLuaStack:OnSendMsg() (at Assets/ToLua/Examples/TestErrorStack/TestLuaStack.cs:277)
  11. UnityEngine.GameObject:SendMessage(String)
  12. TestLuaStack:OnGUI() (at Assets/ToLua/Examples/TestErrorStack/TestLuaStack.cs:481)
复制代码
SendMessage() 等效于直接调用?
SendMessageInLua

    “SendMessageInLua”c# GetFunction(“SendMsgError”).PCall()lua SendMsgError(go)lua go:SendMessage(“OnSendMsg”);
  1. LuaException: this a lua exception
  2. stack traceback:
  3.         [C]: at 0x613c2af0
  4.         [C]: in function 'SendMessage'
  5.         TestErrorStack:38: in function <TestErrorStack:37>
  6.         [C]: in function 'TestArgError'
  7.         TestErrorStack:69: in function <TestErrorStack:68>
  8. TestLuaStack:Test6(IntPtr) (at Assets/ToLua/Examples/TestErrorStack/TestLuaStack.cs:122)
  9. LuaInterface.LuaDLL:lua_pcall(IntPtr, Int32, Int32, Int32)
  10. LuaInterface.LuaState:PCall(Int32, Int32) (at Assets/ToLua/Core/LuaState.cs:755)
  11. LuaInterface.LuaFunction:PCall() (at Assets/ToLua/Core/LuaFunction.cs:96)
  12. TestLuaStack:OnSendMsg() (at Assets/ToLua/Examples/TestErrorStack/TestLuaStack.cs:277)
  13. UnityEngine.GameObject:SendMessage(String)
  14. UnityEngine_GameObjectWrap:SendMessage(IntPtr) (at Assets/Source/Generate/UnityEngine_GameObjectWrap.cs:657)
  15. LuaInterface.LuaDLL:lua_pcall(IntPtr, Int32, Int32, Int32)
  16. LuaInterface.LuaState:PCall(Int32, Int32) (at Assets/ToLua/Core/LuaState.cs:755)
  17. LuaInterface.LuaFunction:PCall() (at Assets/ToLua/Core/LuaFunction.cs:96)
  18. TestLuaStack:OnGUI() (at Assets/ToLua/Examples/TestErrorStack/TestLuaStack.cs:488)
复制代码
和 “SendMessage” 差不多一样。
AddComponent

    “AddComponent”c# GetFunction(“TestAddComponent”).PCall()c# TestAddComponent()c# try { go.AddComponent(); }c# TestInstantiate2.Awake()c# state.ThrowLuaException(e);
  1. Exception: Instantiate exception 2
  2. LuaInterface.LuaStatePtr.ThrowLuaException (System.Exception e) (at Assets/ToLua/Core/LuaStatePtr.cs:607)
  3. TestInstantiate2.Awake () (at Assets/ToLua/Examples/TestErrorStack/TestInstantiate2.cs:16)
  4. UnityEngine.GameObject:AddComponent()
  5. TestLuaStack:TestAddComponent(IntPtr) (at Assets/ToLua/Examples/TestErrorStack/TestLuaStack.cs:237)
  6. LuaInterface.LuaDLL:lua_pcall(IntPtr, Int32, Int32, Int32)
  7. LuaInterface.LuaState:PCall(Int32, Int32) (at Assets/ToLua/Core/LuaState.cs:755)
  8. LuaInterface.LuaFunction:PCall() (at Assets/ToLua/Core/LuaFunction.cs:96)
  9. TestLuaStack:OnGUI() (at Assets/ToLua/Examples/TestErrorStack/TestLuaStack.cs:498)
复制代码
TableGetSet

    “TableGetSet”
TestTableInCo

    “TestTableInCo”c# GetFunction(“TestCoTable”).PCall()lua TestCoTable()lua 运行协程 TestCo(…)lua TestTableInCo(…)c# TestTableInCo()
Instantiate2 Error

    “Instantiate2 Error”c# GetFunction(“Instantiate”).PCall() with go2lua Instantiate()lua UnityEngine.Object.Instantiate(obj)c# TestInstantiate2:Awake()
  1. LuaException: Instantiate exception 2
  2. stack traceback:
  3.         [C]: in function 'Instantiate'
  4.         TestErrorStack:13: in function <TestErrorStack:11>
  5.         [C]: in function 'TestArgError'
  6.         TestErrorStack:69: in function <TestErrorStack:68>
  7. TestInstantiate2:Awake() (at Assets/ToLua/Examples/TestErrorStack/TestInstantiate2.cs:11)
  8. UnityEngine.Object:Instantiate(Object)
  9. UnityEngine_ObjectWrap:Instantiate(IntPtr) (at Assets/ToLua/BaseType/UnityEngine_ObjectWrap.cs:203)
  10. LuaInterface.LuaDLL:lua_pcall(IntPtr, Int32, Int32, Int32)
  11. LuaInterface.LuaState:PCall(Int32, Int32) (at Assets/ToLua/Core/LuaState.cs:755)
  12. LuaInterface.LuaFunction:PCall() (at Assets/ToLua/Core/LuaFunction.cs:96)
  13. TestLuaStack:OnGUI() (at Assets/ToLua/Examples/TestErrorStack/TestLuaStack.cs:573)
复制代码
Instantiate3 Error

    “Instantiate3 Error”c# UnityEngine.Object.Instantiate(go2);c# TestInstantiate2.Awake()
  1. Exception: Instantiate exception 2
  2. LuaInterface.LuaStatePtr.ThrowLuaException (System.Exception e) (at Assets/ToLua/Core/LuaStatePtr.cs:607)
  3. TestInstantiate2.Awake () (at Assets/ToLua/Examples/TestErrorStack/TestInstantiate2.cs:16)
  4. UnityEngine.Object:Instantiate(GameObject)
  5. TestLuaStack:OnGUI() (at Assets/ToLua/Examples/TestErrorStack/TestLuaStack.cs:580)
复制代码
TestCycle

    “TestCycle”c# GetFunction(“TestCycle”).PCall()c# TestCycle()
测试递归调用 luaFunction
TestNull

    “TestNull”c# StartCoroutine(TestCo(action));
c# 中创建协程
TestMulti

    “TestMulti”c# GetFunction(“TestMulStack”).PCall()c# TestMulStack()c# try { TestMul0(); }c# TestMul1()throw
懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Unity开发者联盟 ( 粤ICP备20003399号 )

GMT+8, 2024-11-24 07:39 , Processed in 0.089754 second(s), 25 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表