Fix a bug in function registry, improve docs

This commit is contained in:
2021-12-23 14:38:01 -05:00
parent b4639c70db
commit 82381ada2e
5 changed files with 112 additions and 41 deletions

View File

@@ -497,21 +497,23 @@ void SourceDB::register_lua_builtins() {
LS.getglobaltable(globals);
auto regs = LuaFunctionReg::all();
for (LuaFunctionReg *reg : regs) {
std::string funcname;
std::string classname;
get_reg_name(reg, classname, funcname);
if (classname.empty()) {
LS.rawget(func, globals, funcname);
if (LS.iscfunction(func)) {
reg->set_func(lua_tocfunction(L, func.index()));
}
} else {
LS.rawget(classtab, globals, classname);
if (LS.istable(classtab)) {
LS.rawget(func, classtab, funcname);
if (reg->get_func() == nullptr) {
std::string funcname;
std::string classname;
get_reg_name(reg, classname, funcname);
if (classname.empty()) {
LS.rawget(func, globals, funcname);
if (LS.iscfunction(func)) {
reg->set_func(lua_tocfunction(L, func.index()));
}
} else {
LS.rawget(classtab, globals, classname);
if (LS.istable(classtab)) {
LS.rawget(func, classtab, funcname);
if (LS.iscfunction(func)) {
reg->set_func(lua_tocfunction(L, func.index()));
}
}
}
}
}
@@ -534,7 +536,7 @@ std::string SourceDB::function_docs(const LuaStack &LS0, LuaSlot fn) {
std::string funcname;
get_reg_name(reg, classname, funcname);
std::ostringstream oss;
util::StringVec docs = util::split_lines(reg->get_docs());
util::StringVec docs = util::split_docstring(reg->get_docs());
for (const std::string &line : docs) {
oss << "-- " << line << std::endl;
}