<commit_before>"use strict";

const lua     = require('./lua.js');
const lauxlib = require('./lauxlib.js');

let lua_writestring;
let lua_writeline;
if (typeof process === "undefined") {
    let buff = [];
    lua_writestring = function(s) {
        buff = buff.concat(s);
    };
    lua_writeline = function() {
        console.log(lua.to_jsstring(buff));
        buff = [];
    };
} else {
    lua_writestring = function(s) {
        process.stdout.write(Buffer.from(s));
    };
    lua_writeline = function() {
        process.stdout.write("\n");
    };
}
const luaB_print = function(L) {
    let n = lua.lua_gettop(L); /* number of arguments */
    lua.lua_getglobal(L, lua.to_luastring("tostring", true));
    for (let i = 1; i <= n; i++) {
        lua.lua_pushvalue(L, -1);  /* function to be called */
        lua.lua_pushvalue(L, i);  /* value to print */
        lua.lua_call(L, 1, 1);
        let s = lua.lua_tolstring(L, -1);
        if (s === null)
            return lauxlib.luaL_error(L, lua.to_luastring("'tostring' must return a string to 'print'", true));
        if (i > 1) lua_writestring(lua.to_luastring("\t"));
        lua_writestring(s);
        lua.lua_pop(L, 1);
    }
    lua_writeline();
    return 0;
};
<commit_msg>src/lbaselib.js: Use TextDecoder in lua_writeline<commit_after>"use strict";

const lua     = require('./lua.js');
const lauxlib = require('./lauxlib.js');

let lua_writestring;
let lua_writeline;
if (typeof process === "undefined") {
    let buff = [];
    lua_writestring = function(s) {
        buff = buff.concat(s);
    };
    lua_writeline = function() {
        console.log(new TextDecoder("utf-8").decode(Uint8Array.from(buff)));
        buff = [];
    };
} else {
    lua_writestring = function(s) {
        process.stdout.write(Buffer.from(s));
    };
    lua_writeline = function() {
        process.stdout.write("\n");
    };
}
const luaB_print = function(L) {
    let n = lua.lua_gettop(L); /* number of arguments */
    lua.lua_getglobal(L, lua.to_luastring("tostring", true));
    for (let i = 1; i <= n; i++) {
        lua.lua_pushvalue(L, -1);  /* function to be called */
        lua.lua_pushvalue(L, i);  /* value to print */
        lua.lua_call(L, 1, 1);
        let s = lua.lua_tolstring(L, -1);
        if (s === null)
            return lauxlib.luaL_error(L, lua.to_luastring("'tostring' must return a string to 'print'", true));
        if (i > 1) lua_writestring(lua.to_luastring("\t"));
        lua_writestring(s);
        lua.lua_pop(L, 1);
    }
    lua_writeline();
    return 0;
};

{'fraction_non_alphanumeric': 0.1685569026202581, 'fraction_numerical': 0.007039499413375049, 'mean_word_length': 2.5726256983240225, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '3898305', 'n_tokens_mistral': 957, 'n_tokens_neox': 905, 'n_words': 191}