<commit_before>#include "print.h"

#include <stdio.h>
#include <stdbool.h>

#include <lua.h>

static void printKeyValue(lua_State* L, char startchar) {
  printf("%c %s = %s\n",
      startchar, lua_tostring(L, -2),
      lua_typename(L, lua_type(L, -1)));
}

static void printTable(lua_State* L) {
  bool firstelem = true;
  int luatype;

  lua_insert(L, 2);
  while(lua_next(L, 2) != 0) {
    luatype = lua_type(L, -2);

    // Check if the key it actually a string, because lua_isstring returns
    // true for numbers and we have a different printing for key value
    // tables and index value tables.
    if(luatype == LUA_TSTRING) {
      printKeyValue(L, (firstelem) ? '{' : ',');
      firstelem = false;
    }
    lua_pop(L, 1);
  }
  puts("}");
  lua_remove(L, 2);
}

int laco_printtype(lua_State* L) {
  int status = 0;
  int luatype = lua_type(L, -1);

  if(luatype != LUA_TTABLE) {
    lua_getglobal(L, "print");
    lua_insert(L, 1);

    status = lua_pcall(L, lua_gettop(L) - 1, 0, 0);
  } else {
    printTable(L);
  }

  return status;
}
<commit_msg>Added printable values inside of tables<commit_after>#include "print.h"

#include <stdio.h>
#include <stdbool.h>

#include <lua.h>

inline static const char* toLuaString(lua_State* L) {
  const char* result = NULL;

  lua_getglobal(L, "tostring");
  lua_insert(L, lua_gettop(L) - 1);

  if(lua_pcall(L, 1, 1, 0) == 0) {
    result = lua_tostring(L, -1);
  } else {
    lua_pop(L, 1);
  }

  return result;
}

static void printKeyValue(lua_State* L, char startchar) {
  printf("%c %s = %s\n",
      startchar, lua_tostring(L, -2),
      toLuaString(L));
}

static void printTable(lua_State* L) {
  bool firstelem = true;
  int luatype;

  lua_pushnil(L);
  while(lua_next(L, -2) != 0) {
    luatype = lua_type(L, -2);

    // Check if the key it actually a string, because lua_isstring returns
    // true for numbers and we have a different printing for key value
    // tables and index value tables.
    if(luatype == LUA_TSTRING) {
      printKeyValue(L, (firstelem) ? '{' : ',');
      firstelem = false;
    }
    lua_pop(L, 1);
  }
  puts("}");
  lua_pop(L, 1);
}

int laco_printtype(lua_State* L) {
  int status = 0;
  int luatype = lua_type(L, -1);

  if(luatype != LUA_TTABLE) {
    lua_getglobal(L, "print");
    lua_insert(L, 1);

    status = lua_pcall(L, lua_gettop(L) - 1, 0, 0);
  } else {
    printTable(L);
  }

  return status;
}

{'fraction_non_alphanumeric': 0.1536231884057971, 'fraction_numerical': 0.013664596273291925, 'mean_word_length': 3.101867572156197, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5239824', 'n_tokens_mistral': 1018, 'n_tokens_neox': 953, 'n_words': 240}