MCPcopy Create free account
hub / github.com/9chu/LuaSTGPlus / SafeCallGlobalFunction

Method SafeCallGlobalFunction

LuaSTGPlus/AppFrame.cpp:1600–1635  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1598}
1599
1600bool AppFrame::SafeCallGlobalFunction(const char* name, int retc)LNOEXCEPT
1601{
1602 lua_pushcfunction(L, StackTraceback); // ... c
1603 int tStacktraceIndex = lua_gettop(L);
1604
1605 lua_getglobal(L, name); // ... c f
1606 if (0 != lua_pcall(L, 0, retc, tStacktraceIndex))
1607 {
1608 try
1609 {
1610 wstring tErrorInfo = StringFormat(
1611 L"执行函数'%m'时产生未处理的运行时错误:\n\t%m",
1612 name,
1613 lua_tostring(L, -1)
1614 );
1615
1616 LERROR("脚本错误:%s", tErrorInfo.c_str());
1617 MessageBox(
1618 m_pMainWindow ? (HWND)m_pMainWindow->GetHandle() : 0,
1619 tErrorInfo.c_str(),
1620 L"LuaSTGPlus脚本错误",
1621 MB_ICONERROR | MB_OK
1622 );
1623 }
1624 catch (const bad_alloc&)
1625 {
1626 LERROR("尝试写出脚本错误时发生内存不足错误");
1627 }
1628
1629 lua_pop(L, 2);
1630 return false;
1631 }
1632
1633 lua_remove(L, tStacktraceIndex);
1634 return true;
1635}
1636#pragma endregion
1637
1638#pragma region 游戏循环

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected