More work on moving engine into dlmalloc heap

This commit is contained in:
2022-02-25 19:57:23 -05:00
parent 08f6aa2092
commit ff932dba10
52 changed files with 351 additions and 484 deletions

View File

@@ -3,7 +3,6 @@
#include "wrap-vector.hpp"
#include "wrap-map.hpp"
#include "wrap-set.hpp"
#include "wrap-algorithm.hpp"
#include "wrap-sstream.hpp"
#include "util.hpp"
@@ -13,6 +12,7 @@
#include "source.hpp"
#include "luasnap.hpp"
#include <algorithm>
#include <fstream>
#include <iostream>
@@ -54,10 +54,10 @@ LuaDefine(classname, "classtable", "get the class name from a class table") {
return LS.result();
}
static void get_reg_name(const LuaFunctionReg *reg, eng::string &classname, eng::string &funcname) {
eng::string name = reg->get_name();
static void get_reg_name(const LuaFunctionReg *reg, std::string_view &classname, std::string_view &funcname) {
std::string_view name(reg->get_name());
size_t upos = name.find('_');
if (upos == eng::string::npos) {
if (upos == std::string_view::npos) {
funcname = name;
classname = "";
} else {
@@ -337,11 +337,10 @@ static void source_clear_globals(lua_State *L) {
static void source_load_cfunctions(lua_State *L) {
LuaVar classobj;
LuaStack LS(L, classobj);
auto regs = LuaFunctionReg::all();
for (const LuaFunctionReg *r : regs) {
for (auto r = LuaFunctionReg::All; r != nullptr; r=r->next()) {
lua_CFunction func = r->get_func();
eng::string classname;
eng::string funcname;
std::string_view classname;
std::string_view funcname;
get_reg_name(r, classname, funcname);
if (classname.empty()) {
LS.getglobaltable(classobj);
@@ -497,17 +496,17 @@ void SourceDB::deserialize_source(util::LuaSourceVec *sv, StreamBuffer *sb) {
}
}
// This function should not touch the dlmalloc heap.
void SourceDB::register_lua_builtins() {
lua_State *L = luaL_newstate();
lua_State *L = LuaStack::newstate(lalloc_malloc);
luaL_openlibs(L);
LuaVar globals,classtab,func;
LuaStack LS(L, globals, classtab, func);
LS.getglobaltable(globals);
auto regs = LuaFunctionReg::all();
for (LuaFunctionReg *reg : regs) {
for (auto reg = LuaFunctionReg::All; reg != nullptr; reg=reg->next()) {
if (reg->get_func() == nullptr) {
eng::string funcname;
eng::string classname;
std::string_view funcname;
std::string_view classname;
get_reg_name(reg, classname, funcname);
if (classname.empty()) {
LS.rawget(func, globals, funcname);
@@ -540,8 +539,8 @@ eng::string SourceDB::function_docs(const LuaStack &LS0, LuaSlot fn) {
if (reg == nullptr) {
return "";
}
eng::string classname;
eng::string funcname;
std::string_view classname;
std::string_view funcname;
get_reg_name(reg, classname, funcname);
eng::ostringstream oss;
util::StringVec docs = util::split_docstring(reg->get_docs());