diff options
| author | ame <[email protected]> | 2023-12-18 13:55:13 -0600 |
|---|---|---|
| committer | ame <[email protected]> | 2023-12-18 13:55:13 -0600 |
| commit | 595fd25a80c569d104bc53cbfb9e46654134b4e1 (patch) | |
| tree | 17506097f415d4bddcdf3566d3ce0de08ab9a377 /src/io.c | |
| parent | c691cc98e31e52982a79ffc10b8e91e8c700592b (diff) | |
config and io functions
Diffstat (limited to 'src/io.c')
| -rw-r--r-- | src/io.c | 55 |
1 files changed, 53 insertions, 2 deletions
@@ -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; +} |
