MCPcopy Create free account
hub / github.com/Norbyte/bg3se / ExecLuaCommand

Method ExecLuaCommand

BG3Extender/Extender/Shared/Console.cpp:97–129  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

95}
96
97void 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
131void DebugConsole::HandleCommand(std::string const& cmd)
132{

Callers

nothing calls this directly

Calls 4

CallWithTracebackFunction · 0.85
GetStateMethod · 0.80
ThrowEventMethod · 0.45

Tested by

no test coverage detected