<commit_before>#include <errno.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <sys/sysinfo.h>
#include <sys/utsname.h>
#include <limits.h>
#include <time.h>
#include <locale.h>
#include <mntent.h>

#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
#include "strlcpy.h"

static int pusherror(lua_State *L, const char *error)
{
	lua_pushnil(L);
	lua_pushstring(L, error);
	return 2;
}

static int pusherrno(lua_State *L, const char *error)
{
        lua_pushnil(L);
        lua_pushfstring(L, LUA_QS" : "LUA_QS, error, strerror(errno));
        lua_pushinteger(L, errno);
        return 3;
}

static int Fuptime(lua_State *L)
{
	struct sysinfo info = {0};
	if (sysinfo(&info) != 0) return pusherrno(L, "sysinfo(2) error");
	lua_pushinteger(L, info.uptime);
	return 1;
}

static int Floads(lua_State *L)
{
	int l;
	struct sysinfo info = {0};
	if (sysinfo(&info) == -1) return pusherrno(L, "sysinfo(2) error");
	lua_createtable(L, 3, 3);
	for (l=0; l<3; l++) {
		lua_pushnumber(L, info.loads[l]/65536.00);
		lua_rawseti(L, -2, l+1);
	}
	return 1;
}

static int Fmem(lua_State *L)
{
	struct sysinfo info = {0};
	if (sysinfo(&info) == -1) return pusherrno(L, "sysinfo(2) error");

	lua_createtable(L, 0, 9);

	lua_pushinteger(L, info.mem_unit);
	lua_setfield(L, -2, "mem_unit");

	lua_pushnumber(L, info.freehigh);
	lua_setfield(L, -2, "freehigh");

	lua_pushnumber(L, info.totalhigh);
	lua_setfield(L, -2, "totalhigh");

	lua_pushnumber(L, info.freeswap);
	lua_setfield(L, -2, "freeswap");

	lua_pushnumber(L, info.totalswap);
	lua_setfield(L, -2, "totalswap");

	lua_pushnumber(L, info.bufferram);
	lua_setfield(L, -2, "bufferram");

	lua_pushnumber(L, info.sharedram);
	lua_setfield(L, -2, "sharedram");

	lua_pushnumber(L, info.freeram);
	lua_setfield(L, -2, "freeram");

	lua_pushnumber(L, info.totalram);
	lua_setfield(L, -2, "totalram");
	return 1;
}

static int Fprocs(lua_State *L)
{
	struct sysinfo info = {0};
	if (sysinfo(&info) == -1) return pusherrno(L, "sysinfo(2) error");
	lua_pushinteger(L, info.procs);
	return 1;
}

static int Fsysconf(lua_State *L)
{
	long openmax = sysconf(_SC_OPEN_MAX);
	long procs = sysconf(_SC_NPROCESSORS_CONF);
	long procsonline = sysconf(_SC_NPROCESSORS_ONLN);
	long pagesize = sysconf(_SC_PAGESIZE);
	long physpages = sysconf(_SC_PHYS_PAGES);
	long avphyspages = sysconf(_SC_AVPHYS_PAGES);

	lua_createtable(L, 0, 6);

	lua_pushnumber(L, openmax);
	lua_setfield(L, -2, "openmax");

	lua_pushnumber(L, procs);
	lua_setfield(L, -2, "procs");

	lua_pushnumber(L, procsonline);
	lua_setfield(L, -2, "procsonline");

	lua_pushnumber(L, pagesize);
	lua_setfield(L, -2, "pagesize");

	lua_pushnumber(L, physpages);
	lua_setfield(L, -2, "physpages");

	lua_pushnumber(L, avphyspages);
	lua_setfield(L, -2, "avphyspages");

	return 1;
}
<commit_msg>Use a struct to shorten the function and also increase readability.<commit_after>#include <errno.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <sys/sysinfo.h>
#include <sys/utsname.h>
#include <limits.h>
#include <time.h>
#include <locale.h>
#include <mntent.h>

#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
#include "strlcpy.h"

static int pusherror(lua_State *L, const char *error)
{
	lua_pushnil(L);
	lua_pushstring(L, error);
	return 2;
}

static int pusherrno(lua_State *L, const char *error)
{
        lua_pushnil(L);
        lua_pushfstring(L, LUA_QS" : "LUA_QS, error, strerror(errno));
        lua_pushinteger(L, errno);
        return 3;
}

static int Fuptime(lua_State *L)
{
	struct sysinfo info = {0};
	if (sysinfo(&info) != 0) return pusherrno(L, "sysinfo(2) error");
	lua_pushinteger(L, info.uptime);
	return 1;
}

static int Floads(lua_State *L)
{
	int l;
	struct sysinfo info = {0};
	if (sysinfo(&info) == -1) return pusherrno(L, "sysinfo(2) error");
	lua_createtable(L, 3, 3);
	for (l=0; l<3; l++) {
		lua_pushnumber(L, info.loads[l]/65536.00);
		lua_rawseti(L, -2, l+1);
	}
	return 1;
}

static int Fmem(lua_State *L)
{
	struct sysinfo info = {0};
	if (sysinfo(&info) == -1) return pusherrno(L, "sysinfo(2) error");

	lua_createtable(L, 0, 9);

	lua_pushinteger(L, info.mem_unit);
	lua_setfield(L, -2, "mem_unit");

	lua_pushnumber(L, info.freehigh);
	lua_setfield(L, -2, "freehigh");

	lua_pushnumber(L, info.totalhigh);
	lua_setfield(L, -2, "totalhigh");

	lua_pushnumber(L, info.freeswap);
	lua_setfield(L, -2, "freeswap");

	lua_pushnumber(L, info.totalswap);
	lua_setfield(L, -2, "totalswap");

	lua_pushnumber(L, info.bufferram);
	lua_setfield(L, -2, "bufferram");

	lua_pushnumber(L, info.sharedram);
	lua_setfield(L, -2, "sharedram");

	lua_pushnumber(L, info.freeram);
	lua_setfield(L, -2, "freeram");

	lua_pushnumber(L, info.totalram);
	lua_setfield(L, -2, "totalram");
	return 1;
}

static int Fprocs(lua_State *L)
{
	struct sysinfo info = {0};
	if (sysinfo(&info) == -1) return pusherrno(L, "sysinfo(2) error");
	lua_pushinteger(L, info.procs);
	return 1;
}

static int Fsysconf(lua_State *L)
{
	struct {
		char *name;
		long sc;
	} m[] = {
		{"openmax", sysconf(_SC_OPEN_MAX)},
		{"procs", sysconf(_SC_NPROCESSORS_CONF)},
		{"procsonline", sysconf(_SC_NPROCESSORS_ONLN)},
		{"pagesize", sysconf(_SC_PAGESIZE)},
		{"physpages", sysconf(_SC_PHYS_PAGES)},
		{"avphyspages", sysconf(_SC_AVPHYS_PAGES)}
	};

	lua_createtable(L, 0, 6);
	int c;
        for (c=0; c<sizeof(m)/sizeof(*m); c++) {
		lua_pushnumber(L, m[c].sc);
		lua_setfield(L, -2, m[c].name);
	}
	return 1;
}

{'fraction_non_alphanumeric': 0.17388114453411593, 'fraction_numerical': 0.01797505502567865, 'mean_word_length': 5.058888888888889, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 23, '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': '454369', 'n_tokens_mistral': 2473, 'n_tokens_neox': 2366, 'n_words': 487}