<commit_before>#include "LuaVm.hpp"
#include "compsys/BasicMetaComponent.hpp"
#include "FileSystem.hpp"
#include <array>
#include <luabind/lua_include.hpp>
extern "C" {
#include <lualib.h>
}
#include "LuaUtils.hpp"

#include "Logfile.hpp"
#include "jdConfig.hpp"

namespace {

int pcallf(lua_State* L)
{
    luaL_traceback(L, L, lua_tostring(L, -1), 1);
    return 1;
}

lua_CFunction oldpanicf = nullptr;

int panicf(lua_State* L)
{
    pcallf(L);
    LOG_F(luaU::Error(L, "Lua panic").what());
    return oldpanicf(L);
}

int doDumpVar(lua_State* L)
{
    std::string* const str = static_cast<std::string*>(lua_touserdata(L, 1));
    assert(str);

    std::size_t len;
    char const* s = luaL_tolstring(L, 2, &len);
    str->assign(s, len);
    lua_pop(L, 1);
    return 0;
}
} // anonymous namespace

static char const registryKey = '\0';

/* static */ LuaVm& LuaVm::get(lua_State* L)
{
    lua_rawgetp(L, LUA_REGISTRYINDEX, registryKey);
    LuaVm* vm = static_cast<LuaVm*>(lua_touserdata(L, -1));
    if (!vm)
        throw luaU::Error("no LuaVm registered for the requested state");
    return *vm;
}

LuaVm::LuaVm(std::string const& libConfigFilename)<commit_msg>LuaVm: Some cleanup.<commit_after>#include "LuaVm.hpp"
#include "compsys/BasicMetaComponent.hpp"
#include "FileSystem.hpp"
#include <array>
#include <luabind/lua_include.hpp>
extern "C" {
#include <lualib.h>
}
#include "LuaUtils.hpp"

#include "Logfile.hpp"
#include "jdConfig.hpp"

static int pcallf(lua_State* L)
{
    luaL_traceback(L, L, lua_tostring(L, -1), 1);
    return 1;
}

static lua_CFunction oldpanicf = nullptr;

int panicf(lua_State* L)
{
    pcallf(L);
    LOG_F(luaU::Error(L, "Lua panic").what());
    return oldpanicf(L);
}


static char const registryKey = '\0';

/* static */ LuaVm& LuaVm::get(lua_State* L)
{
    lua_rawgetp(L, LUA_REGISTRYINDEX, registryKey);
    LuaVm* vm = static_cast<LuaVm*>(lua_touserdata(L, -1));
    if (!vm)
        throw luaU::Error("no LuaVm registered for the requested state");
    return *vm;
}

LuaVm::LuaVm(std::string const& libConfigFilename)
{'fraction_non_alphanumeric': 0.15893719806763285, 'fraction_numerical': 0.00676328502415459, 'mean_word_length': 4.478835978835979, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 13, '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': '4495969', 'n_tokens_mistral': 871, 'n_tokens_neox': 844, 'n_words': 175}