#include "debugger.h"

#include <stdio.h>
#include <lua.h>

#include "laco.h"

void laco_print_debug_info(struct LacoState* laco,
                           const char* function_name) {
  lua_State* L = laco_get_laco_lua_state(laco);
  lua_Debug debug_info = {0};

  lua_getfield(L, LUA_GLOBALSINDEX, function_name);

  lua_getinfo(L, ">Sl", &debug_info);

  printf(
    "What:            \t%s\n"
    "Source file:     \t%s\n"
    "Line defined on: \t%d\n"
    "Current line:    \t%d\n",
    debug_info.what, debug_info.source,
    debug_info.linedefined, debug_info.currentline);
}

#include "debugger.h"

#include <lua.h>

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "laco.h"
#include "util.h"

void laco_print_debug_info(struct LacoState* laco,
                           const char* function_name) {
  int i;
  char* namespace;
  lua_State* L         = laco_get_laco_lua_state(laco);
  size_t index         = LUA_GLOBALSINDEX;
  lua_Debug debug_info = {0};

  char* name        = strdup(function_name);
  char** namespaces = laco_split_by(".", name, 0);

  /* Walk down the namespace if there is something to go down */
  for(i = 0; (namespace = namespaces[i]); i++) {
    lua_getfield(L, index, namespace);
    index = lua_gettop(L);
  }

  lua_getinfo(L, ">Sl", &debug_info);

  printf(
    "What:            \t%s\n"
    "Source file:     \t%s\n"
    "Line defined on: \t%d\n"
    "Current line:    \t%d\n",
    debug_info.what, debug_info.source,
    debug_info.linedefined, debug_info.currentline);

  /* Pop off the extra fields from the top of the stack */
  if(i > 1) {
    lua_pop(L, i - 1);
  }

  free(name);
  free(namespaces);
}

Add ablity to look through named tables
Add ablity to look through named tables
