[2026/6/3 星期三 21:55:20] CallLua1 Func:handlerequest 69 luaErr:stack overflow
stack traceback:
.\Envir\Market_Def/npc配置/main.lua: in function 'sendmsg'
.\Envir\Market_Def/npc配置/main.lua:5: in function 'sendmsg'
.\Envir\Market_Def/npc配置/main.lua:5:
🤖 回答引擎: 后端Lua |
🕒 时间: 2026-06-03 21:59:28 |
👁️ 阅读: 4
我是lua后端老师!
小仙,你这个错误是典型的**栈溢出(stack overflow)**问题。从错误堆栈来看,问题出在你的`sendmsg`函数在无限递归调用自己!
看你的代码:
```lua
function send(actor, type, msg)
sendmsg(actor, type, '{"Msg":"' .. msg .. '","FColor":255,"BColor":0,"Type":' .. type .. ',"Time":2}')
end
send(actor, 1, "415315")
```
但是堆栈显示`sendmsg`函数在`main.lua:5`行不断调用自己,这说明你的`sendmsg`函数名可能和引擎内置的`sendmsg`函数冲突了,或者你在其他地方定义了同名的`sendmsg`函数。
**解决方案:**
1. **检查你的`main.lua`文件第5行**,看看是不是定义了`sendmsg`函数,而这个函数内部又调用了自己:
```lua
function sendmsg(actor, type, msg)
sendmsg(actor, type, msg) -- 错误:这里调用了自己,导致无限递归
end
```
2. **正确的做法应该是**调用引擎内置的`sendmsg`函数:
```lua
-- 如果是调用引擎函数,直接使用即可
function send(actor, type, msg)
sendmsg(actor, type, '{"Msg":"' .. msg .. '","FColor":255,"BColor":0,"Type":' .. type .. ',"Time":2}')
end
```
3. **或者避免函数名冲突**,给你的函数起个不同的名字:
```lua
function mySendMsg(actor, type, msg) -- 改为不同的函数名
sendmsg(actor, type, '{"Msg":"' .. msg .. '","FColor":255,"BColor":0,"Type":' .. type .. ',"Time":2}')
end
```
**关键点:**
- 不要定义和引擎内置函数同名的函数,除非你知道自己在做什么
- 如果必须定义,要确保不会递归调用自己
- 使用`release_print()`来调试,查看函数调用流程
把你的`main.lua`文件第5行及附近的代码检查一下,看看是不是函数定义有问题。如果还不明白,可以截图给我看看具体的代码内容!
我是lua后端老师!
小仙,你这个错误是典型的**栈溢出(stack overflow)**问题。从错误堆栈来看,问题出在你的`sendmsg`函数在无限递归调用自己!
看你的代码:
```lua
function send(actor, type, msg)
sendmsg(actor, type, '{"Msg":"' .. msg .. '","FColor":255,"BColor":0,"Type":' .. type .. ',"Time":2}')
end
send(actor, 1, "415315")
```
但是堆栈显示`sendmsg`函数在`main.lua:5`行不断调用自己,这说明你的`sendmsg`函数名可能和引擎内置的`sendmsg`函数冲突了,或者你在其他地方定义了同名的`sendmsg`函数。
**解决方案:**
1. **检查你的`main.lua`文件第5行**,看看是不是定义了`sendmsg`函数,而这个函数内部又调用了自己:
```lua
function sendmsg(actor, type, msg)
sendmsg(actor, type, msg) -- 错误:这里调用了自己,导致无限递归
end
```
2. **正确的做法应该是**调用引擎内置的`sendmsg`函数:
```lua
-- 如果是调用引擎函数,直接使用即可
function send(actor, type, msg)
sendmsg(actor, type, '{"Msg":"' .. msg .. '","FColor":255,"BColor":0,"Type":' .. type .. ',"Time":2}')
end
```
3. **或者避免函数名冲突**,给你的函数起个不同的名字:
```lua
function mySendMsg(actor, type, msg) -- 改为不同的函数名
sendmsg(actor, type, '{"Msg":"' .. msg .. '","FColor":255,"BColor":0,"Type":' .. type .. ',"Time":2}')
end
```
**关键点:**
- 不要定义和引擎内置函数同名的函数,除非你知道自己在做什么
- 如果必须定义,要确保不会递归调用自己
- 使用`release_print()`来调试,查看函数调用流程
把你的`main.lua`文件第5行及附近的代码检查一下,看看是不是函数定义有问题。如果还不明白,可以截图给我看看具体的代码内容!
← 返回问答库