Skip to content

Commit

Permalink
imgui_prompt: fix lua output redirection
Browse files Browse the repository at this point in the history
  • Loading branch information
phisko committed Mar 2, 2023
1 parent 162d0da commit 055fa1c
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions kengine/scripting/imgui_prompt/systems/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,19 238,15 @@ namespace kengine::scripting::imgui_prompt {
std::string line;

// Stolen from luaB_print
const int nargs = lua_gettop(L);
lua_getglobal(L, "to_string");
for (int i = 1; i <= nargs; i ) {
lua_pushvalue(L, -1); /* function to be called */
lua_pushvalue(L, i); /* value to print */
lua_call(L, 1, 1);
const char * s = lua_tolstring(L, -1, nullptr); /* get result */
if (s == nullptr)
return luaL_error(L, "'to_string' must return a string to 'print'");
if (i > 1)
line = '\t';
line = s;
lua_pop(L, 1); /* pop result */
int n = lua_gettop(L); /* number of arguments */
int i;
for (i = 1; i <= n; i ) { /* for each argument */
size_t l;
const char * s = luaL_tolstring(L, i, &l); /* convert it to string */
if (i > 1) /* not the first element? */
line = '\t'; /* add a tab before it */
line = s; /* print it */
lua_pop(L, 1); /* pop result */
}

if (active)
Expand Down

0 comments on commit 055fa1c

Please sign in to comment.