Lots of work on LuaStack

This commit is contained in:
2020-11-27 13:21:07 -05:00
parent f690fb147b
commit 455ba5df87
19 changed files with 715 additions and 527 deletions

View File

@@ -12,10 +12,11 @@
#include <signal.h>
#include <vector>
#include <string>
#include "lpx-stack-manager.hpp"
#include "luastack.hpp"
#include "util.hpp"
#include "lpx-table.hpp"
#include "lpx-classdb.hpp"
#include "table.hpp"
#include "globaldb.hpp"
#include "source.hpp"
// Add another error status.
@@ -174,7 +175,7 @@ static void dotty(lua_State *L)
report(L, status);
if (status == LUA_OK && lua_gettop(L) > 0)
{ /* any result to print? */
lua_getglobal(L, "iprint");
lua_getglobal(L, "pprint");
if (lua_isnil(L, -1)) {
lua_pop(L, 1);
lua_getglobal(L, "print");
@@ -193,26 +194,6 @@ static void dotty(lua_State *L)
fflush(stdout);
}
static void loadmain(lua_State *L)
{
util::stringvec filenames = util::trim_and_uncomment(util::read_lines("syslua/control.lst"));
if (filenames.empty()) {
lua_pushfstring(L, "Cannot read syslua/control.lst");
lua_error(L);
}
for (const auto &fn : filenames) {
std::string full = "syslua/" + fn;
int status = luaL_loadfilex(L, full.c_str(), NULL);
if (status == LUA_OK) {
status = docall(L, 0, 0);
}
if (status != LUA_OK) {
lua_error(L);
}
}
}
static int pmain(lua_State *L)
{
globalL = L;
@@ -231,11 +212,10 @@ static int pmain(lua_State *L)
// luaopen_debug(L); // Not safe for the sandbox.
luaopen_bit(L);
// luaopen_jit(L); // Don't know what it's for.
luaopen_lpx_classdb(L);
luaopen_lpx_globaldb(L);
luaopen_lpx_source(L);
lua_gc(L, LUA_GCRESTART, -1);
loadmain(L);
dotty(L);
return 0;
}