| 339 | static int DFHACK_TOSTRING_TOKEN = 0; |
| 340 | |
| 341 | static 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 | |
| 365 | static int lua_dfhack_print(lua_State *S) |
| 366 | { |
no test coverage detected