| 95 | } |
| 96 | |
| 97 | void DebugConsole::ExecLuaCommand(std::string const& cmd) |
| 98 | { |
| 99 | auto task = [cmd]() { |
| 100 | auto state = gExtender->GetCurrentExtensionState(); |
| 101 | |
| 102 | if (!state) { |
| 103 | ERR("Extensions not initialized!"); |
| 104 | return; |
| 105 | } |
| 106 | |
| 107 | LuaVirtualPin pin(*state); |
| 108 | if (!pin) { |
| 109 | ERR("Lua state not initialized!"); |
| 110 | return; |
| 111 | } |
| 112 | |
| 113 | if (cmd[0] == '!') { |
| 114 | lua::DoConsoleCommandEvent params; |
| 115 | params.Command = cmd.substr(1); |
| 116 | pin->ThrowEvent("DoConsoleCommand", params, false); |
| 117 | } else { |
| 118 | auto L = pin->GetState(); |
| 119 | lua::StaticLifetimeStackPin _(L, lua::LifetimeHandle{}); |
| 120 | lua::ProfilerStackGuard _p(&*pin); |
| 121 | if (luaL_loadstring(L, cmd.c_str()) || lua::CallWithTraceback(L, 0, 0)) { // stack: errmsg |
| 122 | ERR("%s", lua_tostring(L, -1)); |
| 123 | lua_pop(L, 1); |
| 124 | } |
| 125 | } |
| 126 | }; |
| 127 | |
| 128 | SubmitTaskAndWait(serverContext_, task); |
| 129 | } |
| 130 | |
| 131 | void DebugConsole::HandleCommand(std::string const& cmd) |
| 132 | { |
nothing calls this directly
no test coverage detected