* pretty print */
| 50 | * pretty print |
| 51 | */ |
| 52 | static int luaB_pprint(lua_State *L) |
| 53 | { |
| 54 | int n = lua_gettop(L); /* number of arguments */ |
| 55 | int i; |
| 56 | lua_getglobal(L, "tojsonstring"); |
| 57 | for (i = 1; i <= n; i++) { |
| 58 | const char *s; |
| 59 | size_t l; |
| 60 | lua_pushvalue(L, -1); /* function to be called */ |
| 61 | lua_pushvalue(L, i); /* value to print */ |
| 62 | lua_call(L, 1, 1); |
| 63 | s = lua_tolstring(L, -1, &l); /* get result */ |
| 64 | if (s == nullptr) |
| 65 | return luaL_error(L, "'tojsonstring' must return a string to 'pprint'"); |
| 66 | if (i > 1) luaL_writestring(L, "\t", 1); |
| 67 | luaL_writestring(L, s, l); |
| 68 | lua_pop(L, 1); /* pop result */ |
| 69 | } |
| 70 | luaL_writeline(L); |
| 71 | return 0; |
| 72 | } |
| 73 | |
| 74 | static int luaB_exit_repl(lua_State *L) |
| 75 | { |
nothing calls this directly
no test coverage detected