MCPcopy Create free account
hub / github.com/DFHack/dfhack / lua_print_fmt

Function lua_print_fmt

library/LuaTools.cpp:341–363  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

339static int DFHACK_TOSTRING_TOKEN = 0;
340
341static std::string lua_print_fmt(lua_State *L)
342{
343 /* Copied from lua source to fully replicate builtin print */
344 int n = lua_gettop(L); /* number of arguments */
345 lua_rawgetp(L, LUA_REGISTRYINDEX, &DFHACK_TOSTRING_TOKEN);
346
347 std::stringstream ss;
348
349 for (int i=1; i<=n; i++) {
350 lua_pushvalue(L, -1); /* function to be called */
351 lua_pushvalue(L, i); /* value to print */
352 lua_call(L, 1, 1);
353 const char *s = lua_tostring(L, -1); /* get result */
354 if (s == NULL)
355 luaL_error(L, "tostring must return a string to print");
356 if (i>1)
357 ss << '\t';
358 ss << s;
359 lua_pop(L, 1); /* pop result */
360 }
361
362 return ss.str();
363}
364
365static int lua_dfhack_print(lua_State *S)
366{

Callers 3

lua_dfhack_printFunction · 0.85
lua_dfhack_printlnFunction · 0.85
lua_dfhack_printerrFunction · 0.85

Calls 5

lua_gettopFunction · 0.85
lua_rawgetpFunction · 0.85
lua_pushvalueFunction · 0.85
luaL_errorFunction · 0.85
strMethod · 0.45

Tested by

no test coverage detected