| 587 | } |
| 588 | |
| 589 | std::optional<int> State::LoadScript(STDString const & script, STDString const & name, int globalsIdx) |
| 590 | { |
| 591 | int top = lua_gettop(L); |
| 592 | |
| 593 | /* Load the file containing the script we are going to run */ |
| 594 | int status = luaL_loadbufferx(L, script.c_str(), script.size(), name.c_str(), "text"); |
| 595 | if (status != LUA_OK) { |
| 596 | LuaError("Failed to parse script: " << lua_tostring(L, -1)); |
| 597 | lua_pop(L, 1); /* pop error message from the stack */ |
| 598 | return {}; |
| 599 | } |
| 600 | |
| 601 | #if LUA_VERSION_NUM <= 501 |
| 602 | if (globalsIdx != 0) { |
| 603 | lua_pushvalue(L, globalsIdx); |
| 604 | lua_setfenv(L, -2); |
| 605 | } |
| 606 | #endif |
| 607 | |
| 608 | /* Ask Lua to run our little script */ |
| 609 | LifetimeStackPin _(L, lifetimeStack_); |
| 610 | ProfilerStackGuard _p(this); |
| 611 | status = CallWithTraceback(L, 0, LUA_MULTRET); |
| 612 | if (status != LUA_OK) { |
| 613 | LuaError("Failed to execute script: " << lua_tostring(L, -1)); |
| 614 | lua_pop(L, 1); // pop error message from the stack |
| 615 | return {}; |
| 616 | } |
| 617 | |
| 618 | return lua_gettop(L) - top; |
| 619 | } |
| 620 | |
| 621 | void State::OnGameSessionLoading() |
| 622 | { |
no test coverage detected