<commit_before>"use strict";

global.WEB = false;

const fs             = require('fs');
const child_process  = require('child_process');
const tmp            = require('tmp');

const lua            = require("../src/lua.js");
const lauxlib        = require("../src/lauxlib.js");

const toByteCode = function (luaCode) {
    var luaFile = tmp.fileSync();

    fs.writeSync(luaFile.fd, luaCode);

    child_process.execSync(`luac -o ${luaFile.name}.bc ${luaFile.name}`);

    let b = fs.readFileSync(`${luaFile.name}.bc`);
    let dv = new DataView(b.buffer.slice(b.byteOffset, b.byteOffset + b.byteLength));

    return dv;
};

const getState = function(luaCode) {
    let L = lauxlib.luaL_newstate();

    lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));

    return L;
};

module.exports.getState = getState;
module.exports.toByteCode = toByteCode;<commit_msg>tests/tests.js: throw errors if unable to load code<commit_after>"use strict";

global.WEB = false;

const fs             = require('fs');
const child_process  = require('child_process');
const tmp            = require('tmp');

const lua            = require("../src/lua.js");
const lauxlib        = require("../src/lauxlib.js");

const toByteCode = function (luaCode) {
    var luaFile = tmp.fileSync();

    fs.writeSync(luaFile.fd, luaCode);

    child_process.execSync(`luac -o ${luaFile.name}.bc ${luaFile.name}`);

    let b = fs.readFileSync(`${luaFile.name}.bc`);
    let dv = new DataView(b.buffer.slice(b.byteOffset, b.byteOffset + b.byteLength));

    return dv;
};

const getState = function(luaCode) {
    let L = lauxlib.luaL_newstate();
    if (!L)
        throw Error("unable to create lua_State");

    if (lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode)) !== lua.LUA_OK)
        return Error(lua.lua_tojsstring(L, -1));

    return L;
};

module.exports.getState = getState;
module.exports.toByteCode = toByteCode;
{'fraction_non_alphanumeric': 0.15538057742782152, 'fraction_numerical': 0.0005249343832020997, 'mean_word_length': 3.2927927927927927, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1595305', 'n_tokens_mistral': 664, 'n_tokens_neox': 644, 'n_words': 132}