aboutsummaryrefslogtreecommitdiff
path: root/src/io.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/io.c')
-rw-r--r--src/io.c55
1 files changed, 53 insertions, 2 deletions
diff --git a/src/io.c b/src/io.c
index 6d07a44..9b84804 100644
--- a/src/io.c
+++ b/src/io.c
@@ -1,9 +1,9 @@
#include "io.h"
#include "stdlib.h"
#include "stdio.h"
-#include "string.h"
+#include "config.h"
#include "stdint.h"
-#include "unistd.h"
+#include "table.h"
int l_readfile(lua_State* L){
size_t len;
@@ -75,3 +75,54 @@ int l_error(lua_State* L){
return 0;
}
+void print_indentation(int i){
+ for(int z = 0; z < i; z++) printf(" ");
+}
+
+void i_pprint(lua_State* L, int indent){
+ int last_idx = lua_gettop(L);
+ const char* type = lua_typename(L,lua_type(L,-1));
+ int t = lua_type(L,-1);
+ switch(lua_type(L,-1)){
+ 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;
+ printf("{");
+ if(!skip) printf("\n");
+ lua_pushnil(L);
+ for(;lua_next(L,last_idx) != 0;){
+ if(lua_type(L,-2) == LUA_TSTRING){
+ print_indentation(indent);
+ printf(" %s"color_gray":"color_reset, lua_tostring(L,-2));
+ }
+ i_pprint(L,indent+1);
+ printf(",");
+ if(!skip) printf("\n");
+
+ lua_pop(L,1);
+ }
+
+ print_indentation(indent);
+ printf("}");
+ break;
+ case LUA_TSTRING:
+ print_indentation(indent);
+ printf("\"%s\"", lua_tostring(L,-1));
+ break;
+ default:
+ print_indentation(indent);
+ printf(color_yellow"%s"color_reset, lua_tostring(L,-1));
+ }
+
+ if(_print_type){
+ if(lua_istable(L,last_idx)) printf(color_gray" : <%s:%lu>"color_reset,type,i_len(L,last_idx));
+ else printf(color_gray" : <%s>"color_reset,type);
+ }
+
+}
+int l_pprint(lua_State* L){
+ i_pprint(L,0);
+ printf("\n");
+ return 0;
+}