#include "stdafx.h"
#include <windows.h>
#include <string>
#include <iostream>
#include <sstream>
using namespace std;
extern "C"
{
#include "lua.h"
#include "lualib.h"
#include <lauxlib.h>
};
int pcall_callback_err_fun(lua_State* L)
{
lua_Debug debug= {};
int ret = lua_getstack(L, 2, &debug); // 0是pcall_callback_err_fun自己, 1是error函数, 2是真正出错的函数
lua_getinfo(L, "Sln", &debug);
std::string err = lua_tostring(L, -1);
lua_pop(L, 1);
std::stringstream msg;
msg << debug.short_src << ":line " << debug.currentline;
if (debug.name != 0) {
msg << "(" << debug.namewhat << " " << debug.name << ")";
}
msg << " [" << err << "]";
lua_pushstring(L, msg.str().c_str());
return 1;
}
int main()
{
lua_State * L = luaL_newstate(); //创建lua运行
Lua的pcall错误处理
最新推荐文章于 2023-11-12 03:28:32 发布