aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/io.md3
-rw-r--r--src/config.c20
-rw-r--r--src/config.h3
-rw-r--r--src/io.c2
-rw-r--r--tt.lua2
5 files changed, 20 insertions, 10 deletions
diff --git a/docs/io.md b/docs/io.md
index d009c8d..74fe3a6 100644
--- a/docs/io.md
+++ b/docs/io.md
@@ -14,9 +14,10 @@ llib.io.pprint({a = 5, b = {9, 9, 22}})
#### config options
-- print_type (0) - whether or not to print item type (0 or 1)
+- print_type (0 | true) - whether or not to print item type (0 or 1)
- max_depth (2) - maximum depth that will not be collapsed
- start_nl_at (3) - maximum depth that will be kept in-line
+- collapse_all (0 | false) - skip all newlines
### error/warn/log/debug
diff --git a/src/config.c b/src/config.c
index 2fd4455..25919d1 100644
--- a/src/config.c
+++ b/src/config.c
@@ -1,9 +1,12 @@
#include "config.h"
+#include "io.h"
#include <string.h>
int _print_type = 0;
int _max_depth = 2;
int _start_nl_at = 3;
+int _collapse_all = 0;
+
int _file_malloc_chunk = 512;
int get_config_map(const char* key){
@@ -17,13 +20,16 @@ int l_set(lua_State* L) {
luaL_checktype(L, 1, LUA_TTABLE);
get_config_map("print_type");
lua_pushnil(L);
- for(;lua_next(L,1) != 0;){
- int ind = get_config_map(lua_tostring(L,-2));
+ for(;lua_next(L,1) != 0;){
+ int ind = get_config_map(lua_tostring(L,-2));
- if(ind != -1) {
- *config_map[ind].value = lua_tonumber(L,-1);
- }
- lua_pop(L,1);
+ if(ind != -1) {
+ *config_map[ind].value = lua_tonumber(L,-1);
+ lua_pushnumber(L, 1);
+ return 1;
}
- return 0;
+ lua_pop(L,1);
+ }
+ lua_pushnumber(L, 0);
+ return 1;
}
diff --git a/src/config.h b/src/config.h
index 15a4342..d50774d 100644
--- a/src/config.h
+++ b/src/config.h
@@ -4,6 +4,8 @@
extern int _print_type;
extern int _max_depth;
extern int _start_nl_at;
+extern int _collapse_all;
+
extern int _file_malloc_chunk;
struct str_to_int {
@@ -15,6 +17,7 @@ static struct str_to_int config_map[] = {
{"file_chunksize", &_file_malloc_chunk},
{"print_type", &_print_type},
{"max_depth", &_max_depth},
+ {"collapse_all", &_collapse_all},
{"start_nl_at", &_start_nl_at},
{NULL,NULL}
};
diff --git a/src/io.c b/src/io.c
index 70771b6..ed59dfa 100644
--- a/src/io.c
+++ b/src/io.c
@@ -95,7 +95,7 @@ void i_pprint(lua_State* L, int indent){
case LUA_TTABLE:
print_indentation(indent);
if(indent >= _max_depth && _max_depth >= 0) {printf("{"color_gray"..."color_reset"}"); break;}
- int skip = i_len(L,last_idx) < _start_nl_at;
+ int skip = i_len(L,last_idx) < _start_nl_at || _collapse_all;
printf("{");
if(!skip) printf("\n");
lua_pushnil(L);
diff --git a/tt.lua b/tt.lua
index 640e78c..d52b00f 100644
--- a/tt.lua
+++ b/tt.lua
@@ -2,7 +2,7 @@ require "llib"
local s = llib.array.split("0 5 3 10"," ")
local b = {a=5}
-llib.config.set({max_depth=-1});
+llib.config.set({max_depth=-1,collapse_all=1});
llib.io.pprint({5,{"what"},{55,55,33,2,5,5,5},{{55,5,8},9},3,{5,{meow=3}},{meow={5,5}}})
--llib.io.pprint(llib.array.len(b))