#define linit_c
#define LUA_LIB
#include "lprefix.h"
#include <stddef.h>
#include <cstring>
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
static const luaL_Reg loadedlibs[] = {
{LUA_GNAME, luaopen_base},
{LUA_LOADLIBNAME, luaopen_package},
#ifndef PLUTO_NO_COROLIB
{LUA_COLIBNAME, luaopen_coroutine},
#endif
{LUA_TABLIBNAME, luaopen_table},
#ifndef PLUTO_NO_FILESYSTEM
{LUA_IOLIBNAME, luaopen_io},
#endif
{LUA_OSLIBNAME, luaopen_os},
{LUA_STRLIBNAME, luaopen_string},
{LUA_MATHLIBNAME, luaopen_math},
{LUA_UTF8LIBNAME, luaopen_utf8},
#ifndef PLUTO_NO_DEBUGLIB
{LUA_DBLIBNAME, luaopen_debug},
#endif
{NULL, NULL}
};
LUALIB_API void luaL_openlibs (lua_State *L) {
const luaL_Reg *lib;
for (lib = loadedlibs; lib->func; lib++) {
luaL_requiref(L, lib->name, lib->func, 1);
lua_pop(L, 1);
}
luaL_getsubtable(L, LUA_REGISTRYINDEX, LUA_PRELOAD_TABLE);
for (const Pluto::PreloadedLibrary* lib : Pluto::all_preloaded) {
lua_pushcfunction(L, lib->init);
lua_setfield(L, -2, lib->name);
}
lua_pop(L, 1);
#ifndef PLUTO_DONT_LOAD_ANY_STANDARD_LIBRARY_CODE_WRITTEN_IN_PLUTO
const auto startup_code = R"EOC(
pluto_use "0.6.0"
class exception
__name = "pluto:exception"
function __construct(public what)
local caller
local i = 2
while true do
caller = debug.getinfo(i)
if caller == nil then
error("exception instances must be created with 'pluto_new'", 0)
end
++i
if caller.name == "Pluto_operator_new" then
caller = debug.getinfo(i)
break
end
end
self.where = $"{caller.short_src}:{caller.currentline}"
error(self, 0)
end
function __tostring()
return $"{self.where}: {tostring(self.what)}"
end
end
function instanceof(a, b)
return a instanceof b
end
)EOC";
luaL_loadbuffer(L, startup_code, strlen(startup_code), "Pluto Standard Library");
lua_call(L, 0, 0);
#endif
}